Is there an effective way I can create an integer array with a string of integers?

I’d like to have a string made of integers like that :

012030
312341
413413
524213
623424

This is a visual way of representing a grid, (like on a chess game or a candy-crush type game)

How can I take every single one of these integers and populate an array of type int[6,5]?

Thanks

2 Answers

2

You don’t have to create a new class to do it as @KMKxJOEY1 says, you can use real nested arrays.

string myString = "123" + '

’ + “456” + ’
’ + “789”;

string[] words = myString.Split('

');

int[][] intArray = new int[words.Length][];
for (int i = 0; i < words.Length; ++i)
{
    intArray _= new int[words*.Length];*_

for (int j = 0; j < words*.Length; ++j)*
{
intArray_[j] = System.Convert.ToInt32(“” + words*[j]);
}
}*

Assuming the numbers have only one digit and the separator between rows is a new line._

A nested array in C#:

public intArray[] array;
public class intArray{int[] array}

Hi there, thanks for your response. I don't understand exactly how it would work. Can you just add 2 or 3 lines to your code to give me a hint? Thanks a lot!

–