Advertisement
Guest User

Untitled

a guest
May 26th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. public int[] RemoveCommasFromStringOfNumbers(string numbersAndCommas) {
  2.     int[] numbers = new int[6]
  3.     int x = 0;
  4.     string tempNumber;
  5.     if (numbersAndCommas.Length != 0) {
  6.         for (int i = 0; i < numbersAndCommas.Length; i++) {
  7.             if (numbersAndCommas[i].isDigit) {  // if char is a digit
  8.                 tempNumber += numbersAndCommas[i];
  9.             } else {                            // else push to numbers array, because we hit a comma
  10.                 if (x < 6) {                   
  11.                     numbers[x] = Int32.Parse(tempNumber)
  12.                     x++;
  13.                     tempNumber = "";
  14.                 }
  15.             }
  16.         }
  17.     }
  18.     return numbers;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement