编写小程序,测试你的严谨思维能力

有随便的一篇英文文章,把文章里的所有的英文单词都调取出来,比如 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=0;i<matches.Count;i++)
14             {
15                 Console.WriteLine(matches[i].Groups[1].Value);
16             }
17 
18             Console.ReadKey();
19         }
20     }

用了正则,只能应付例句中的单词和标点,如果有更繁杂的标点如:,! ' &等等之类的,请大家不断给出不同的英文段落和测试程序,看看谁的更完善。

原文地址:https://www.cnblogs.com/ztotem/p/1505626.html