日期:2014-05-20  浏览次数:20715 次

怎么从文件里把单词一个一个的读出来,不要读空格
rt

------解决方案--------------------
先把文件按行读出来,然后再用正则把空格、逗号、句号等为分界把单词提出来就可以了。

也可以用split( " ")等分割单词。
------解决方案--------------------
兄弟们都养成了光说不练的官僚习性。我先把试验过的贴出来,后来者多补充!
string s = "hello! How old are you? ";
Regex re = new Regex(@ "\w+ ", RegexOptions.IgnoreCase);
foreach(Match m in re.Matches(s))
{

string s1 = m.Groups[0].Value.ToString();

------解决方案--------------------
StreamReader sr=new StreamReader( "test.txt ",Encoding.Default);
string str=sr.ReadToEnd();
sr.Close();
string[] strs=System.Text.RegularExpressions.Regex.Split(str,@ "\s+ ");