国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#英文單詞分類統計示例分享

2020-01-24 02:46:14
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

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();
        }
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 峡江县| 区。| 马边| 勃利县| 山阳县| 朔州市| 遂川县| 泾源县| 巫山县| 罗源县| 阿图什市| 仁布县| 山阳县| 胶州市| 东丰县| 盐亭县| 新绛县| 平湖市| 旌德县| 丰县| 平阳县| 阿合奇县| 高台县| 大名县| 高阳县| 澜沧| 弥渡县| 化州市| 巴东县| 颍上县| 明水县| 合山市| 酉阳| 宁海县| 太康县| 宜君县| 昭平县| 秭归县| 宿州市| 视频| 射洪县|