将c#split string与多个分隔符一起使用

时间:2011-09-08 09:01:31

标签: c# string split

我有这个字符串

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

我需要在c#中拆分字符串,每次出现,\u000B都应该是一个新单词。

我试过了:

string[] newString = myString.Split(",\u000B");

但它没有用,我怎么能这样做?

4 个答案:

答案 0 :(得分:10)

将split命令更改为:

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

如果要在分割时保留空条目,请使用StringSplitOptions.None

答案 1 :(得分:3)

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

在我的机器上运行

答案 2 :(得分:2)

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

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

答案 3 :(得分:0)

您可以使用短字符转义符号:“,\ v”代替。

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