Let’s say I have this string var:
string strData = "1|2|3|4||a|b|c|d"
Then, I make a Split:
string[] strNumbers = strData.Split("||"); //something like this, I know It's not this simple
I need two separate parts, each one containing this:
//strNumbers -> {"1","2","3","4"},{"a","b","c","d"}
So that after that, I could do this:
string[] strNumArray = strNumbers[0].Split('|');
//strNumArray -> '1', '2', '3', '4'
And same with the other part (letters).
Is it possible? to make this double split with the same character, but the first time the character is repeated twice?.
Thanks.
PD. I’m using C#.
It’ll work fine, your syntax is just off.
So first, your declarations are off. You want the [] on the type, not the name.
Second, on String.Split, there is an overload that takes in a string array and a StringSplitOptions. Just trying to do “||” will call the param char overload, which is invalid.
So try this:
You can change the StringSplitOptions to RemoveEmptyEntries if you wanted.