如何处理名称的自动字符大小写(名字、姓氏)?
可能的重复:
有没有人有一个好的正确案例算法
我目前处于不幸的是,我要求以正确的字符大小写显示从各种来源(Excel、Access 等)作为批处理过程的一部分加载的用户名。
例如,如果名称加载为“JOHN DOE”,则它应显示为“John Doe”。
显然,对于像 McDonald、O'Reilly、LeBron 等这样的名字,这很快就会变得非常复杂......
在研究这个问题时,我唯一能找到的就是建议以全部大写形式显示名称,而这个解决方案比显示更受欢迎像麦当劳、奥莱利和勒布朗这样的名字,我仍然想确保在返回给他们“这就是你所能拥有的一切”之前我已经完成了尽职调查。
是否有任何图书馆(开源或付费)可以帮助解决这个问题?我意识到它很可能不是完美的,但如果它能覆盖 95%~99% 的情况,那就可以了。
提前致谢。
Possible Duplicate:
Does anyone have a good Proper Case algorithm
I am currently in the unfortunate position of having a requirement thrust on me to display names of users that are loaded as part of a batch process from various sources (Excel, Access, etc...) with the correct character casing.
For example, if a name was loaded as "JOHN DOE" it should display as "John Doe".
Obviously this gets very complicated very quickly with names like McDonald, O'Reilly, LeBron, etc...
When researching this, the only thing I could find was advice saying to display the names in all caps, while this solution is preferred over showing names like Mcdonald, O'reilly and Lebron I would still like to be sure that I've done my due diligence before returning to them with "this is all you can have".
Are there any libraries out there (open source or paid) that could help accommodate this? I realize that it most likely cannot be perfect, but if it could cover 95~99% of the cases, then that should do fine.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
您可以在 Globalization 命名空间中使用 TitleCase:
string myName = "JOHN QUINCY PUBLIC"; System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; System.Globalization.TextInfo textInfo = cultureInfo.TextInfo; string convertedName = textInfo.ToTitleCase(myName.ToLower()); Console.WriteLine(convertedName);
将生成“John Quincy Public”
它不会按照您想要的方式处理撇号。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以查看 Perl 的 NameCase 模块,它正是这样做的。
You could check out Perl's NameCase module, which does exactly this.