源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#英文单词分类统计示例分享

  • 时间:2022-10-18 09:26 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#英文单词分类统计示例分享
[u]复制代码[/u] 代码如下:
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();         }     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部