弦乐随着String.ToUpperInvariant正常化() [英] Normalization of Strings With String.ToUpperInvariant()

查看:220
本文介绍了弦乐随着String.ToUpperInvariant正常化()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前存储的字符串标准化版本在我的SQL Server数据库小写。例如,在我的用户表,我有一个用户名和LoweredUserName场。根据不同的情况下,我要么使用T-SQL的LOWER()函数或C#的String.ToLower()方法来生成的用户名的小写版本来填充LoweredUserName字段。据微软的指引并的 Visual Studio的code分析规则CA1308 ,我应该使用C的#String.ToUpperInvariant()代替ToLower将()。据微软称,这既是一个性能和全球化的问题:转换为大写是安全的,而转换为小写会导致信息丢失(例如,的土耳其'I'问题)。

I am currently storing normalized versions of strings in my SQL Server database in lower case. For example, in my Users table, I have a UserName and a LoweredUserName field. Depending on the context, I either use T-SQL's LOWER() function or C#'s String.ToLower() method to generate the lower case version of the user name to fill the LoweredUserName field. According to Microsoft's guidelines and Visual Studio's code analysis rule CA1308, I should be using C#'s String.ToUpperInvariant() instead of ToLower(). According to Microsoft, this is both a performance and globalization issue: converting to upper case is safe, while converting to lower case can cause a loss of information (for example, the Turkish 'I' problem).

如果我移动到使用ToUpperInvariant字符串正常化,我将不得不改变我的数据库架构为好,因为我的架构是基于的Microsoft's ASP.NET成员框架(见<一href=\"http://stackoverflow.com/questions/98908/what-is-the-point-of-the-lowered-columns-in-asp-net-membership-tables\">this相关的问题),这串规范化为小写的。

If I move to using ToUpperInvariant for string normalization, I will have to change my database schema as well, since my schema is based on Microsoft's ASP.NET Membership framework (see this related question), which normalizes strings to lower case.

不是微软自打嘴巴告诉我们在C#中使用大写正常化,而它在成员表和过程本身code使用小写正常化?我应该切换一切大写正常化或只是继续使用小写正常化?

Isn't Microsoft contradicting itself by telling us to use upper case normalization in C#, while it's own code in the Membership tables and procedures is using lower case normalization? Should I switch everything to upper case normalization, or just continue using lower case normalization?

推荐答案

要回答你的第一个问题,是微软是有点不一致。要回答你的第二个问题,直到您已经确认这是导致你的应用程序的瓶颈没有不转什么。

To answer your first question, yes Microsoft is a bit inconsistent. To answer your second question, no do not switch anything until you have confirmed that this is causing a bottleneck in your application.

想想多少,你可以向前进步做出你的项目上浪费时间切换的一切,而不是。你的开发时间要比储蓄更有价值,你会从这种变化得到的。

Think how much forward progress you can make on you project instead of wasting time switching everything. Your development time is much more valuable than the savings you would get from such a change.

记住:

premature优化是编程中所有的邪恶(或至少大部分)的根源。 - 高德纳

Premature optimization is the root of all evil (or at least most of it) in programming. - Donald Knuth

这篇关于弦乐随着String.ToUpperInvariant正常化()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆