简体   繁体   中英

use c# split string with Multiple delimiters

I have this string

"abc,\ defgh,\ jh,\ kl"

And i need to split the string in c#, every time ,\ 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); 

适用于我的机器

        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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM