string str = "How are you?Fine,Thank you!"; char[] removeChar = {' ','?',',','!'}; string[] words = str.Split(removeChar,StringSplitOptions.RemoveEmptyEntries); 还可以这样写:string[] words = str.Split(‘,’,’?’’!’);//这行代码也可以去掉那些字符(?/!/,),但不能去除空格(‘ ’)。 Console.WriteLine("这a句?话°共有{0}个单词?,words.Length); Console.WriteLine("这几个单词分别为:"); for (int i = 0; i < words.Length; i++) { Console.WriteLine(words[i]); } |