I have strings like "1\t2\r\n3\t4"
and I'd like to split them as:
new string[][] { { 1, 2 }, { 3, 4 } }
Basically, it should be split into lines, and each line should be split into tabs. I tried using the following, but it doesn't work:
string toParse = "1\t2\r\n3\t4";
string[][] parsed = toParse
.Split(new string[] {@"\r\n"}, StringSplitOptions.None)
.Select(s => s.Split('\t'))
.ToArray();
Remove the '@':
string toParse = "1\t2\r\n3\t4";
string[][] parsed = toParse
.Split(new string[] {"\r\n"}, StringSplitOptions.None)
.Select(s => s.Split('\t'))
.ToArray();
The @ makes the string include the backslashes, instead of the character they represent.
string str = "1\t2\r\n3\t4";
Int32[][] result = str.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
.Select(s => s.Split('\t').Select(s2 => int.Parse(s2)).ToArray())
.ToArray();
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With