手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#英文单词分类统计示例分享
c#英文单词分类统计示例分享
摘要:复制代码代码如下:usingSystem;usingSystem.Linq;namespaceConsoleApplication1{///...

复制代码 代码如下:

using System;

using System.Linq;

namespace ConsoleApplication1

{

/// <summary>

/// 给出一段英文,分类统计(如:长度为4的单词有2个:time,well)

/// </summary>

class Program

{

static void Main(string[] args)

{

string source = "Do one thing at a time,and do well";//已知英文语句

string[] stringArray = source.Split(new char[] { ' ', ',' });

var result = stringArray.GroupBy(s => s.Length).Select(s => new {

Lenght = s.Select(x => x).FirstOrDefault().Length,

Count = s.Count(),

StringItems = s.Select(x => x)

});

foreach (var s in result)

{

string strResult = string.Empty;

foreach (var item in s.StringItems)

{

strResult += string.IsNullOrEmpty(strResult) ? item : " , " + item;

}

Console.WriteLine(string.Format("长度为{0}的单词有{1}个:{2}", s.Lenght, s.Count, strResult));

}

Console.ReadKey();

}

}

}

【c#英文单词分类统计示例分享】相关文章:

c# 共享状态的文件读写实现代码

C#文件后缀名的详细介绍

c#读取xml文件到datagridview实例

c#读取文件详谈

C#简单的加密类实例

C# 泛型类(函数)的实例化小例子

C# 观察者模式实例介绍

c#图片添加水印的实例代码

c# 应用事务的简单实例

c# 值类型实例构造器

精品推荐
分类导航