开发者

use c# split string with Multiple delimiters

开发者 https://www.devze.com 2023-04-03 06:09 出处:网络
I have this string \"abc,\\u000Bdefgh,\\u000Bjh,\\u000Bkl\" 开发者_如何学PythonAnd i need to split the string in c#, every time ,\\u000B appearsshould be a new word.

I have this string

"abc,\u000Bdefgh,\u000Bjh,\u000Bkl"

开发者_如何学Python

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?


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.


string[] newString = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.None); 

Works on my machine


        string myString = "abc,\u000Bdefgh,\u000Bjh,\u000Bkl";

        string[] a = myString.Split(new string[] { ",\u000B" }, StringSplitOptions.RemoveEmptyEntries);


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
0

精彩评论

暂无评论...
验证码 换一张
取 消