- Home /
Double Parse a text file into 2d array or jagged array
(C#) I'm trying to double parse this text file I have into a 2d array or jagged array. The text file I have just consist of this"
name,definition; name,definition; name,definition;
More or less, I'm really asking how to fill the 2d array or jagged array when looping. This is as far as I got, I know im supposed to fill whatever data structure im using after the second split but I just dont know what to type to fill a 2d array or jagged array
void Double(TextAsset TextToParse)
{
string [] keyValues = TextToParse.text.Split(';');
foreach(string keyValue in keyValues)
{
string [] kv = keyValue.Split(",");
// Don't know what to put here to fill a 2d array/ jagged array
}
}
Answer by Brian@Artific · Jul 09, 2013 at 08:21 PM
The syntax is straightforward - each dimension is represented by another set of brackets at the end of your variable (e.g., parsedValues[0][0]).
Before your loop, you'll need:
string[][] parsedValues = new string[keyValues.Length][];
int i = 0;
... and within it ...
parsedValues[i] = kv;
i++;
im getting an error on this line.
string[][] parsedValues= new string[keyValues.Length][2];
error CS0178: Invalid rank specifier: expected `,' or `]'
Sorry, that '2' shouldn't have been there - I've edited my answer.
Your answer
Follow this Question
Related Questions
Parse.com and Unity integration 1 Answer
Splitting textasset into an array and binary search 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers