日期:2014-05-19  浏览次数:20668 次

char[] aaa = "##".ToCharArray;为什么报错?想用"##"来分割一个字符串怎么做?
char[]   aaa   =   "## ".ToCharArray;为什么报错?

用 "## "来分割一个字符串怎么做?

string[]   spi   =   i.Split( "## ".ToCharArray);
这样报错?

------解决方案--------------------
string[] spi = i.Split( "## ");

System.Text.RegularExpressions.Regex.Split(i, "## ");
------解决方案--------------------
2.0中
string testStr= "fd#fds##fdsa##fdsafd ";
string[] result = testStr.Split(new string[] { "## " }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in result)
{
richTextBox2.Text += s + "\n ";
}

输出
fd#fds
fdsa
fdsafd

用Regex.Split
string testStr= "fd#fds##fdsa##fdsafd ";
string[] result = System.Text.RegularExpressions.Regex.Split(testStr, "## ");
foreach (string s in result)
{
richTextBox1.Text += s + "\n ";
}

输出结果同上