用正则吧 。可以分得更细一些。不仅仅是根据空格。还能根据标点符号啊之类的。呵呵 。参考一下下面的代码吧:把 “Hello,How Are You!”拆分成4个单词。 static void Main(string[] args) { string str = "Hello,How Are You!"; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\b\w+\b"); System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str); foreach (System.Text.RegularExpressions.Match m in mc) { Console.WriteLine(m.Value ); } }
using System;public class SplitTest { public static void Main() { string words = "This is a list of words with a bit of punctuation."; string [] split = words.Split(new Char [] {' '}); foreach (string s in split) { if (s.Trim() != "") Console.WriteLine(s); } }}