Reputation: 2559
I have this string
"abc,\u000Bdefgh,\u000Bjh,\u000Bkl"
And i need to split the string in c#, every time ,\u000B
appears should be a new word.
I tried this:
string[] newString = myString.Split(",\u000B");
but it didnt work, how can i do this?
Upvotes: 2
Views: 6270
Reputation: 28290
You could use the short character escape notation: ",\v" instead.
Short UTF-16 Description
--------------------------------------------------------------------
\' \u0027 allow to enter a ' in a character literal, e.g. '\''
\" \u0022 allow to enter a " in a string literal, e.g. "this is the double quote (\") character"
\\ \u005c allow to enter a \ character in a character or string literal, e.g. '\\' or "this is the backslash (\\) character"
\0 \u0000 allow to enter the character with code 0
\a \u0007 alarm (usually the HW beep)
\b \u0008 back-space
\f \u000c form-feed (next page)
\n \u000a line-feed (next line)
\r \u000d carriage-return (move to the beginning of the line)
\t \u0009 (horizontal-) tab
\v \u000b vertical-tab
Upvotes: 0
Reputation:
string[] newString = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.None);
Works on my machine
Upvotes: 3
Reputation: 60694
Change your split command to this:
string[] newString = ip.Split(new[]{",\u000B"}, StringSplitOptions.RemoveEmptyEntries);
Or use, StringSplitOptions.None
if you want to preserve empty entries while splitting.
Upvotes: 9
Reputation: 30095
string myString = "abc,\u000Bdefgh,\u000Bjh,\u000Bkl";
string[] a = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.RemoveEmptyEntries);
Upvotes: 2