字符串按首字母分组并ToDictionary的实现

时间:2022-08-31 21:51:38

  这是一道面试题目,要求实现字符串按首字母分组并ToDictionary输出,当时没有做出来,后面研究了一下,现在将这道题的几种实现方式记录下来。

首先初始化数据源,是一个List<string>对象。如下代码。

//数据源
List<string> list = new List<string>
{
"Beijing", "Shanghai", "Tianjin", "Chongqing", "Harbin", "Dalian", "Qingdao", "Xi'an",
"Dunhuang", "Nanjing", "Wuxi", "Suzhou", "Yangzhou", "Zhenjiang", "Hangzhou", "Xitang",
"Zhoushan", "Chun'an", "Qiandaohuzhen", "Shaoxing", "Huangshan", "Jiujiang", "Xiamen",
"* Shan", "Zhangjiajie", "Chengdu", "Shenzhen", "Zhuhai", "Guangzhou", "Guilin",
"Kunming", "Xishuangbanna", "Dali", "Lijiang", "Guiyang", "Urumqi", "Turpan", "Lhasa"
};

第一种分组方法,使用正则表达式,代码如下。

        /// <summary>
/// 使用正则表达式匹配
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private static string GetGroupNameByRegex(char str)
{
string sInput = str.ToString();
if (Regex.IsMatch(sInput, "[a-gA-G]", RegexOptions.IgnoreCase))
{
return "A-G";
}
if (Regex.IsMatch(sInput, "[h-nH-N]", RegexOptions.IgnoreCase))
{
return "H-N";
}
return "O-Z";
}

第二种方法,直接比较两个char,代码如下。

        /// <summary>
/// 方法二:使用字符的ASCII码大小匹配
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private static string GetGroupNameByCharASCII(char str)
{
if ((str >= 'a' && str <= 'g') || (str >= 'A' && str <= 'G')) //char可以隐式地转换为int
{
return "A-G";
}
if ((str >= 'h' && str <= 'n') || (str >= 'H' && str <= 'N'))
{
return "H-N";
}
return "O-Z";
}

注意,两个char之所以能直接比较大小,实际上char先被转换成了int,也就是对应的ASCII码,然后才进行比较大小的。

第三种方法,实际上跟第二种方法相同,只不过在方法二的基础上进行了优化,代码如下。

        /// <summary>
/// 方法二的升级版
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private static string GetGroupNameByCharASCII1(char str)
{
char newChar = Char.ToLower(str);
//if (newChar >= 'o')
//{
// return "O-Z";
//}
//if (newChar>='h')
//{
// return "H-N";
//}
//return "A-G";
return newChar >= 'o' ? "O-Z" : newChar >= 'h' ? "H-N" : "A-G";
}

需要注意的是,方法三的写法,多个if...else...语句可以使用三元操作符来化简,使代码更优雅。

输出结果,代码如下。

var query = list.GroupBy(p =>
{
return GetGroupNameByRegex(p[]);
}).ToDictionary(p => p.Key, p => p);
foreach (var item in query)
{
Console.WriteLine("{0}", item.Key);//IGrouping<TKey,TValue>
foreach (var subItem in item.Value)
{
Console.WriteLine(" {0}", subItem);
}
}
Console.ReadKey();

输出结果截图如下。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgEAAALxCAIAAABKFuIvAAAgAElEQVR4nO3dd/wrVZ038Py77u6zfZ/d9VndtayKvSs2XBt2QBEFCwoK0puKNC+9dwHpSFNQUBBhRdAoShMUEKwoostFLPRygat5/hiM85uWyWSSOcl5v1/ndV+Tk8mZ5MLrfPKdmZPbu+WWW9bc/ZZ37n3zJdf99pY/6ZW76LIfZdqeh56c70y3Cy7+dkWreOE1P/j5hzbbbtiu+cHPk5ck/SeedlbSU/bywje20WG3DgaDPw4GD/9hsOKhwb0rBnfcN/jtXYNbbh/84reDH986uP5Xg+/eNLj8p4PzrrznVR86o2zwk04/+6c33/bjm2794c9uuf4nv7zuR7/43g0/u+q6n1zxvR9edvUN37ryum9efk3/0u8eetSJ7b420z5/7oXJCEm79oc3fe+Gn139/Z9+59ofJ0N97pyvHHncqa2/Nt9OOffywWAwGAz++MfBypV/ePChh++7b8Udd9933Y9+9YI3bNjuqwr/Jm/46a+Gf5NXXvOjzN/kJVdcm/n7vOK6m2+48dcV7bgzv3HFdTcP919/mwPW3+aAijfz6Ke8PLOd7sn0F7bqMcuGKttt2FnzWHXawz9Z46YLnv2H23Zeful7BnceftP5z1xx64kr/7jygYcevuO+h5ff8dCNv35w1bdsPHKcjx73662O/O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IiXOgAgXuoAgHipAwDipQ4AiJc6ACBe6gCAeKkDAOKlDgCIlzoAIF7qAIB4qQMA4tVmHVD47wH4yX6AYLVZB8gAgPmiDgCIlzoAIF7uCwKIl/uCAOKlDgCIlzoAIF7qAIB4qQMA4qUOAIiXOgAgXuoAgHipAwDipQ4AiJc6ACBe6gCAeKkDAOKlDgCIlzoAIF7qAIB4JXN4zbbaaqvJAIDFkczpdSTzvAwAWBzpOb26yQCARSMDAOIlAwDiJQMA4rVkTi/ZQQYALKZMHZB/VgYALKz8uaD0UzIAYJEVXg/oFa0dkwEAi8Y1YYB4yQCAeMkAgHjJAIB4JRN4TTIAYKGsNqaqDKhTTQzbuPtrmrbYbbXVVmv2j5n4M/3nuH/nDf5LVWXAqB+gfsS4+wOLLXOewZ8T/jnW33nLGVBniHH31zRtsVsyJ3Q+dS7An+mNOn/nDf5jyQBN01pu6oDW/6z/dz5uGzsDejV+d0LTtJibOmB6dUB+Bk7/nY/1nylzoFoZkFx6Lju2DNA07Xp1wDTrgMJJ+PrxM2AwGCxbtiw9/ugMGN5+VP3fW9O0yJs6YKp1QPU8XKclATBeBqRvQS07tgzQNO16dcD064D8VFw/A9IBkB5fHaBpWjtNHRBsHZCvAMbIgOtdD9A0rUZTB7T+57BNcj0gEwBjXw8YvoPq/96apkXe1AFTrQMq/s4r/qPkA6BhBlQcWwZomna9OmCadcDIv/PCVhYA6fFlgKZp7TR1wPTqgOq/88KnqisAGaBpWstNHdD6n/X/zjOtIgBGnwsq+9XpvHH3BxabOqCtqX+sv/OxAmBZdQYATKLzCXQB/mzwdz5WAJRmwPU1Sg9N0zRt3ltBBgwAiEY2AzRN07TYmgzQNE2Lt/UmvA0AgPnVm8J9AQDMh94qq67zlBevvcqq6yTNtm3btm3Hs/3/AaSIW+51VYRIAAAAAElFTkSuQmCC" alt="" />

字符串按首字母分组并ToDictionary的实现的更多相关文章

  1. 取字符串拼音首字母(js)

    //取字符串拼音首字母 function makePy(str) { if (typeof(str) != "string") throw new Error(-1, " ...

  2. 本地化下按首字母分组排序的神器——UILocalizedIndexedCollation

    最近在整一个很简单的通讯录相关的项目,通讯录当然就少不了按首字母或者汉字拼音首字母分组排序索引.因为按照我一贯的的做法,都是想要做成更通用的.支持本地化的,所以这就纠结了,世界各地的语言啊我去,我顶多 ...

  3. 用Java将字符串的首字母转换大小写

    在项目开发的时候会需要统一字符串的格式,比如首字母要求统一大写或小写,那用Java如何实现这一功能?下面一起来学习学习. 话不多说,直接上代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 ...

  4. 小tips:JS&sol;CSS实现字符串单词首字母大写

    css实现: text-transform:capitalize; JS代码一: String.prototype.firstUpperCase = function(){ return this.r ...

  5. fastjson将bean转成字符串时首字母变小写问题

    一个项目需求要求返回值为JSON格式,且大多数字段是首字母大写,还有些是类似N_TX这样的格式,在输出这样的结果时遇到了问题,由于时间紧,就直接拷贝需要的结果字段建立JavaBean类,本以为最后直接 ...

  6. PHP获取中英文字符串的首字母

    使用场景:在对地区进行筛选时,我们经常会看到按照英文字母进行筛选定位,起初想着是数据表里存储上地区与首字母关联关系,但是觉得太麻烦,然后就想着根据地区名称来获取首字母,然后对地区进行分组,由此便用到了 ...

  7. 如何将js字符串变成首字母大写其余小写

    有时候会接收到一些大小写不规则的字符串,如"JAMES"."alice"."Amy"等,如何将他们统一的变成首字母大写其余小写的形式呢? 思 ...

  8. sqlserver取字符串拼音首字母

    sqlserver 使用函数获取一个字符串的拼音首字母 create function dbo.fn_getpinyin ( @str nvarchar(max) ) returns nvarchar ...

  9. Oracle提取中文字符串拼音首字母函数

    通过oracle的NLSSORT函数对汉字按照拼音排序,然后根据汉字的区间返回对应的首字母. 效果1,获取拼音简码: 效果2,获取姓名首字母: 创建函数: /* 获取拼音简码函数 */ CREATE ...

随机推荐

  1. Mono的简单例子

    一直对移动端开发有些兴趣,但苦于不会Java,好在终于找到了个好玩的. 安装方法略了,先建立一个玩玩 不多说,贴代码了,需要注意的只有些JAVA和C#写法不太一样的地方,不细介绍了,因为没什么经验,乱 ...

  2. 2014江西理工大学C语言程序竞赛初级组

    坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...

  3. linux查看硬件环境

    一:查看cpu more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  4. Git提交代码到远程服务器

    1.下载Git 不用说了,这个是必须的,也是最简单的步骤,地址如下: http://git-scm.com/download 这里会提供三个版本的下载地址,读者可以自行查找. 2.创建代码库 远程的代 ...

  5. jenkins部署前后端分离的vue项目

    1 General Name: 变量名. 类似给分支起一个名字的意思, 可随意取 Description: 描述, 非必填 Parameter Type: 选择 Branch or Tag Defau ...

  6. vs widows服务的开发

    最近再做一个视频管理系统,发现用户提交时实时转换视频非常慢.于是有了通过建立一个单独的服务.通过服务定时查询数据库,是否有需要转换的视频来解决问题.现把过程记录下来,已供参考 1.新建widows 服 ...

  7. oracle日志相关的表

    SELECT * FROM all_objects t where  object_name like '%EN_CONCAT_IM%';DBA_HIST_SQLTEXTDBA_HIST_SQLSTA ...

  8. 无用之flask

    Oldboy s4 Flask   Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收 ...

  9. &lbrack;中英对照&rsqb;How PCI Express Works &vert; PCIe工作原理

    How PCI Express Works | PCIe工作原理 PCI Express is a high-speed serial connection that operates more li ...

  10. MVC 使用IOC实现

    实现步骤: 1. 实现IDependencyResolver接口并通过DependencyResolver.SetResolver告知MVC,将部分类型实例解析工作交由IoC容器来处理: using ...