建议用正则表达式,下面是大概 List<string> ret = new List<string>(); Regex r = new Regex(@"\w+"); Match m = r.Match(iinputstring); while(m.Success) { ret.Add(m.ToString()); m = m.NextMatch; } return ret;代码是在这里手写的,有的地方可能有问题,你试一下
已测试 string test_cmd = "hello, nice to meeting you!"; string [] b = test_cmd.Split(' ');
应该用 string str = "hello,nice to neeting you!"; string[] b = str.Split(new char[]{' ',',','!','.'} 要把所有的标点符号都写到char[]数组中才可以取道正确的单词
{
return System.Text.RegularExpressions.Regex.Replace(Input, @"[\s]+", " ").Split(' ');
}
然后再根据string [] b = a.Split(' ');
List<string> ret = new List<string>();
Regex r = new Regex(@"\w+");
Match m = r.Match(iinputstring);
while(m.Success)
{
ret.Add(m.ToString());
m = m.NextMatch;
}
return ret;代码是在这里手写的,有的地方可能有问题,你试一下
string test_cmd = "hello, nice to meeting you!";
string [] b = test_cmd.Split(' ');
string str = "hello,nice to neeting you!";
string[] b = str.Split(new char[]{' ',',','!','.'}
要把所有的标点符号都写到char[]数组中才可以取道正确的单词