有随便的一篇英文文章,把文章里的所有的英文单词都调取出来,比如 I am a chinese.So i love China.......等等。。。 输出的结果就是
I
am
a
chinese
.
so
i
love
China
.
.......
抛土坷垃引玉,我的解法:
1 using System;
2 using System.Collections.Generic;
3 using System.Text.RegularExpressions;
4
5 class Program
6 {
7 static void Main(string[] args)
8 {
9 string strSource = " I am a chinese.So i love China.";
10
11 MatchCollection matches = Regex.Matches(strSource, @"(([\w]+)|([\.]{1})(?=[^\.]{1})|([\.]{1})(?=[\.]{6})|([\.]{6,6}))");
12
13 for (int i&#61;0;i<matches.Count;i&#43;&#43;)
14 {
15 Console.WriteLine(matches[i].Groups[1].Value);
16 }
17
18 Console.ReadKey();
19 }
20 }
2 using System.Collections.Generic;
3 using System.Text.RegularExpressions;
4
5 class Program
6 {
7 static void Main(string[] args)
8 {
9 string strSource &#61; " I am a chinese.So i love China.";
10
11 MatchCollection matches &#61; Regex.Matches(strSource, &#64;"(([\w]&#43;)|([\.]{1})(?&#61;[^\.]{1})|([\.]{1})(?&#61;[\.]{6})|([\.]{6,6}))");
12
13 for (int i&#61;0;i<matches.Count;i&#43;&#43;)
14 {
15 Console.WriteLine(matches[i].Groups[1].Value);
16 }
17
18 Console.ReadKey();
19 }
20 }
用了正则&#xff0c;只能应付例句中的单词和标点&#xff0c;如果有更繁杂的标点如:,! &#39; &等等之类的,请大家不断给出不同的英文段落和测试程序&#xff0c;看看谁的更完善。