字符串按首字母分组并ToDictionary的实现
这是一道面试题目,要求实现字符串按首字母分组并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",
"Wuyi 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/OXGB/3kfXteO2ybHPL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DipQ4AiJc6ACBe6gCAeKkDAOKlDgCIlzoAIF7qAIB4qQMA4tVmHVD47wH4yX6AYLVZB8gAgPmiDgCIlzoAIF7uCwKIl/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的实现的更多相关文章
- 取字符串拼音首字母(js)
//取字符串拼音首字母 function makePy(str) { if (typeof(str) != "string") throw new Error(-1, " ...
- 本地化下按首字母分组排序的神器——UILocalizedIndexedCollation
最近在整一个很简单的通讯录相关的项目,通讯录当然就少不了按首字母或者汉字拼音首字母分组排序索引.因为按照我一贯的的做法,都是想要做成更通用的.支持本地化的,所以这就纠结了,世界各地的语言啊我去,我顶多 ...
- 用Java将字符串的首字母转换大小写
在项目开发的时候会需要统一字符串的格式,比如首字母要求统一大写或小写,那用Java如何实现这一功能?下面一起来学习学习. 话不多说,直接上代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 ...
- 小tips:JS/CSS实现字符串单词首字母大写
css实现: text-transform:capitalize; JS代码一: String.prototype.firstUpperCase = function(){ return this.r ...
- fastjson将bean转成字符串时首字母变小写问题
一个项目需求要求返回值为JSON格式,且大多数字段是首字母大写,还有些是类似N_TX这样的格式,在输出这样的结果时遇到了问题,由于时间紧,就直接拷贝需要的结果字段建立JavaBean类,本以为最后直接 ...
- PHP获取中英文字符串的首字母
使用场景:在对地区进行筛选时,我们经常会看到按照英文字母进行筛选定位,起初想着是数据表里存储上地区与首字母关联关系,但是觉得太麻烦,然后就想着根据地区名称来获取首字母,然后对地区进行分组,由此便用到了 ...
- 如何将js字符串变成首字母大写其余小写
有时候会接收到一些大小写不规则的字符串,如"JAMES"."alice"."Amy"等,如何将他们统一的变成首字母大写其余小写的形式呢? 思 ...
- sqlserver取字符串拼音首字母
sqlserver 使用函数获取一个字符串的拼音首字母 create function dbo.fn_getpinyin ( @str nvarchar(max) ) returns nvarchar ...
- Oracle提取中文字符串拼音首字母函数
通过oracle的NLSSORT函数对汉字按照拼音排序,然后根据汉字的区间返回对应的首字母. 效果1,获取拼音简码: 效果2,获取姓名首字母: 创建函数: /* 获取拼音简码函数 */ CREATE ...
随机推荐
- JSON Web Token in ASP.NET Web API 2 using Owin
In the previous post Decouple OWIN Authorization Server from Resource Server we saw how we can separ ...
- 浅谈react受控组件与非受控组件
引言 最近在使用蚂蚁金服出品的一条基于react的ant-design UI组件时遇到一个问题,编辑页面时input输入框会展示保存前的数据,但是是用defaultValue就是不起作用,输入框始终为 ...
- centos下配置nginx遇到的一些基本的坑
作为一个用.net的渣渣,常年混迹在window平台下,对Linux啥都不懂.随着.net core开源.跨平台后,也开始学习下linux. 在Desktop/Webs下放了一个index.html的 ...
- 【BZOJ2001】 [Hnoi2010]City 城市建设
BZOJ2001 [Hnoi2010]City 城市建设 Solution 我们考虑一下这个东西怎么求解? 思考无果...... 咦? 好像可以离线cdq,每一次判断一下如果这条边如果不选就直接删除, ...
- 在vue项目中stylus的安装及使用
Stylus是一个CSS预处理器. Stylus安装包安装: dell@DESKTOP-KD0EJ4H MINGW64 /f/gsff-frone $ cnpm install stylus --sa ...
- 无图形界面安装CentOS
有些插在ATCA中的x86刀片虽然是提供了Micro HDMI显示接口的,但是可能由于厂家出于节省成本的考量,没有给板卡配备显卡,那么在无图形界面下安装系统,就成为一个运维人员应知的一件事情.这里我们 ...
- IQueryable与IEnumerable
IEnumerable: 从服务器处取回所有数据,在客户端根据过滤条件进行过滤再返回结果. IQueryable: 从服务器处进行过滤,直接返回过滤后的结果.
- Oracle的卸载过程步骤
用Oracle自带的卸载程序不能从根本上卸载Oracle,从而为下次的安装留下隐患,那么怎么才能完全卸载Oracle呢?那就是直接注册表清除,步骤如下: 1. 开始->设置->控制面板-& ...
- Intent的那些事儿
请原谅我用这么文艺的标题来阐释一颗无时无刻奔腾着的2B青年的心.可是今天要介绍的Intent绝不2B,甚至在我看来,或许还有些许飘逸的味道,至于飘逸在哪里呢?那我们就好好来剖析剖析Intent和它的好 ...
- Javac常量池的解读
interface IA{ public void md(); } public class Test07 implements IA{ final double d = 2.0d; final fl ...