手机
当前位置:查字典教程网 >编程开发 >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#图片添加水印的实例代码

C# 骑士飞行棋的源码(分享)

c#读取文件详谈

c# 获得局域网主机列表实例

C# 观察者模式实例介绍

C#位移的介绍与例子

C#简单的加密类实例

C#中通过API实现的打印类 实例代码

精品推荐
分类导航