-1

I have gone through this solution. But this is not solving my problem. Let's say I have a string:

var aString = "0 -1 12 456 -512";

I want to convert this string to an int array like:

var convertedArray = [0, -1, 12, 456, -512];

How should I approach to solve this problem?

2

2 Answers 2

1

You can simply do this:

var stringNumbers = aString.Split(' ');
var numbers = new int[stringNumbers.Length];
for (int i = 0; i < stringNumbers.Length; i++)
    numbers[i] = Convert.ToInt32(stringNumbers[i]);
Sign up to request clarification or add additional context in comments.

Comments

1
var convertedArray = Array.ConvertAll(aString.Split(' '), int.Parse);

1 Comment

Code only answer are not answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.