I have an comma separated string like this:
string myString = "1,a,b,C1,,#2,d,e,C2,,#3,f,g,C3,,#4,h,i,C4,,#";
This is basically the data from an csv file where I am using reader to read from file.
In the above string ',' represents the data delimeter while '#' represents EOL of the file.
myString = myString.TrimEnd('#'); //Removing extra # in the end.
//Result of above 1,a,b,C1,,#2,d,e,C2,,#3,f,g,C3,,#4,h,i,C4,,
I want to convert the above into multidimentional array, loop through it reading value of each row data and create my own json.
So I started with the below code. This would result me with row and column count.
int rowCount = result.TrimEnd('#').Split('#').Count();
int colCount = result.TrimEnd('#').Split('#')[0].TrimEnd(',').Split(',').Length;
//Defining my object which I want to fill.
JObject myObject = new JObject();
Below I want to loop through row and column getting data value from each row and column
for (int row = o ; row <= rowCount; row++)
{
for (int col = 0; col <= colCount; col++)
{
//So here I want to do something like:
var rowValue = multiArray[row][col];
//After getting the row value below is the logic to add to my object
if(col == 0)
{
myObject.Add("first", rowValue);
}
else if(col == colCount)
{
myObject.Add("last", rowValue);
}
else
{
myObject.Add(col, rowValue);
}
}
}
So my question is how can I create the multidimentional array "multiArray" in my code.
Example of my json:
{
"first": 1
"1": a,
"2": b,
"last": C1
},
{
"first": 2
"1": c,
"2": d,
"last": C2
}
"1,a,b,C1,,#2,d,e,C2,,#3,f,g,C3,,#4,h,i,C4,,#"