我们给大家总计了C#中判断英文单词个数的方法以及排序的技巧,对此有需要的朋友可以测试下。
正文
C#判断单词个数方法总结
方法一:
判断英文单词个数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
using System; namespace FindWord { class Program { static void Main( string [] args) { string space = " " ; string str = "hello world" + space; int count = 0; bool start = false ; for ( int i=0;i<str.Length;i++) { if (Char .IsLetter(str[i])) { start = true ; } if (!Char.IsLetter(str[i])&&start) { count++; start = false ; } } Console.WriteLine(count); Console.ReadLine(); } } } |
方法二:
C#统计英文字符串中单词个数思路如下:
1.使用的Hashtable(高效)集合,记录每个单词出现的次数
2.采用ArrayList对Hashtable中的Keys按字母序排列
3.排序使用插入排序(稳定)
发表评论