using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace vc_test { class Program { static void Main(string[] args) { Program myprograme = new Program(); myprograme.myway(" ha!yeah,heh.you are my sister?hei hei"); Console.ReadKey(); } void myway(string str) { string[] strcoll=new string[]{" ","'","!",";",".","?",","}; //这是分割标识符,如有还有什么要加的特殊符号,只要在数组中添加就可以了。 string[] strcoll2 = null; ArrayList arr = new ArrayList(); strcoll2 = str.Split(strcoll,System .StringSplitOptions .None ); for (int i = 0; i < strcoll2.Length; i++) { if (!strcoll2[i].Trim().Equals("")) { arr.Add(strcoll2[i].ToString()); } } Console.WriteLine("字符串是:{0}", str); Console.WriteLine("字符串中单词的数量是:{0}", arr.Count ); } } }