I've the following string:
string text = "Hello && my || Name & is | Tom"
Now I want to split the string into different parts without the logical operators between the words. I've tried the following, but I get only one string with the whole text.
String[] result= Regex.Split(text, @"\&&\||\&\|");
Whats wrong?
The expected output is an array with 5 strings:
No regex solution, just splitting:
String[] result = text.Split(new Char[] { '|', '&' }, StringSplitOptions.RemoveEmptyEntries);
Change your code to,
String[] result= Regex.Split(text, @"\s*[|&]+\s*");
This splits your input according to one or more | or & symbols. \s* matches zero or more spaces , and [|&]+ matches one or more | or & symbols.
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