## 2 replies

Last post Jun 27, 2019 05:13 AM by Yang Shen

• Saraqueen

Member

3 Points

3 Posts

### Converting group comma delimited string into 2D Array

Can anyone help me to convert group Comma Delimited String into 2D Array. please give me small example for better understanding. Thank in advance.

Participant

840 Points

497 Posts

### Re: Converting group comma delimited string into 2D Array

Hello Saraqueen,

https://stackoverflow.com/questions/56606579/group-comma-delimited-string-into-range-groups-2-dimentional-array/56624260#56624260

Thank you.

Ashish Jain
• Yang Shen

Contributor

3130 Points

983 Posts

### Re: Converting group comma delimited string into 2D Array

Jun 27, 2019 05:13 AM|Yang Shen|LINK

Hi Saraqueen,

To convert a string into a two-dimensional array, you can first use the Split() method to split the string into Int-type values and store them in a one-dimensional array.

Then read the values in a one-dimensional array and store them in a two-dimensional array.

You can refer to below codes in a C# console demo:

```static void Main(string[] args)
{
int r = 2, c = 5, n = 20;
string str = "1,2,3,4,5,6,7,8,9,0";
string[] Arr = str.Split(',');//Separating strings based on commas
int[] IArr = new int[n];//Define one-dimensional array
int[,] CommArr = new int[r, c];//Define two-dimensional array
for (int i = 0; i < Arr.Length; i++)
{
IArr[i] = Convert.ToInt32(Arr[i]);//Store values in one-dimensional array
}
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
CommArr[i, j] = IArr[i * c + j];//Store values in two-dimensional array
Console.Write(CommArr[i, j] + " ");//display data
}
Console.WriteLine("\n");
}
}```

Best Regard,

Yang Shen