I have lines (string type) of numbers like "23 78 53 4 94 32 148 31". I need to put them into int array. Here's the lame code I wrote, but it doesn't work properly:
int currentArrayValue=0;
int currentChar=0;
for (int i = 0; i < text1.Length; i++)
{
if (text1[i] != ' ')
{
currentChar++;
continue;
}
else
{
for (int k = 1; k <=currentChar; k++)
{
if (k == 1) Array[currentArrayValue] = text1[i - currentChar];
else if (k == 2) Array[currentArrayValue] = text1[i - currentChar] * 10;
else if (k == 3) Array[currentArrayValue] = text1[i - currentChar] * 100;
}
currentArrayValue++;
}
}
It can be a one-, two- or three-digit number.
it doesn't work properlyis not a helpful description of the problem. What do you expect to get? What did you get instead? Are you getting an error/exception? If so, what is and where is it happening? Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers.Convert.ToInt32()on each one. You can either use a list or just allocate a new array of length,splitStringArray.Length