13,046,533 members (69,436 online)
Rate this:
See more:
hi all,

how to convert string like "[[2,3],[4,5],[3,4]]" to two dimensional integer array.
Posted 8-Oct-12 18:38pm
Updated 8-Oct-12 18:40pm
v3
Member 9039168 9-Oct-12 0:45am

Where is the sting? Can you explain with an example
Varun Sareen 9-Oct-12 1:16am

you cannot convert this string into two dimensional array. Try to put your question clearly here.

What is the issue your are facing?
Narra sreenu 9-Oct-12 6:26am

I have a two dimensional array in java script like

var exArray = [[2, 3], [3, 4], [5, 6]];
These array values are stored in a hidden variable using json object.
document.getElementById("hdnArray").value = JSON.stringify(exArray);

In Code side, the hidden variable value as "[[2, 3], [3, 4], [5, 6]]".

Now I want to convert these hidden variable value into two dimensional array with out using spliting operation.

Rate this:

## Solution 1

Hi Narra Sreenu,

```int[,] myArray = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

String res = "[";
int row = 4, column = 2;
for (int i = 0; i < row; i++)
{
res = res + "[";
for (int j = 0; j < column; j++)
{
res = res + myArray[i, j] + ",";
}
res = res.TrimEnd(',');
res = res + "],";
}
res = res.TrimEnd(',');
res = res + "]";```

Be Happy Be Coding.
Rate this:

## Solution 2

Hi dear ,
use this

```var sb = new StringBuilder();
sb.Append("1,1,2,2,0,0,a,b,c,d,1,1,2,2,0,1,e,f,g,h,1,1,2,2,0,1,x,y,x,z");
const int k = 3;
var items = sb.ToString().Split(',');
var len = items.Length;
var columns = ((len - 1) / k) + 1; //or (len/k) if (len%k==0)
string[,] result = new string[columns, k];
int c = -1;
int r = -1;
for (int i = 0; i < len; i++)
{
string item = items[i];
c = (c + 1) % columns;
if (c == 0)
{
r++;
}
result[c, r] = item;
}```

Top Experts
Last 24hrsThis month
 Graeme_Grant 140 Richard MacCutchan 130 OriginalGriff 115 Kornfeld Eliyahu Peter 95 Atlapure Ambrish 40
 OriginalGriff 4,868 RickZeeland 1,864 ppolymorphe 1,738 F-ES Sitecore 1,553 Dave Kreskowiak 1,379