用C#怎么编写---一篇英文文章中的所有的英文单词都调取出来

来源:百度知道 编辑:UC知道 时间:2024/05/13 09:39:53
我的意思是 有随便的一篇英文文章,我想把文章里的所有的英文单词都调取出来,比如 I am a chinese.So i love China.......等等。。。 输出的结果就是
I
am
a
chinese
.
so
i
love
China
.
.......
谢谢大家帮忙,有消息的话 请发到我的MSN:orangor@hotmail.com

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string strSource = " I am a chinese.So i love China.......";

MatchCollection matches = Regex.Matches(strSource, @"(([\w]+)|([\.]{1})(?=[^\.]{1})|([\.]{1})(?=[\.]{6})|([\.]{6,6}))");

for (int i=0;i<matches.Count;i++)
{
Console.WriteLine(matches[i].Groups[1].Value);
}

Console.ReadKey();
}
}
}

每个单词后都有一个空格,所以就可以将文章以空格为分隔点分开,然后存到数组中,最后在打印出来就可以了
string a = "sadh lkasjd alksdj你的文章";
string[] Arr = a.Split[" "];\\将文章以空格为分隔点分开,然后存到数组中
for (int i = 0; i <= Arr.Length - 1;