简体   繁体   English

没有toUpper / toLower的最有效的大写/小写字符串的方法

[英]Most efficient way to uppercase/lowercase a string without toUpper/toLower

在不使用toUpper / toLower的情况下,在.Net中大写/小写字符串的最佳方法是什么?

myString.ToLowerInvariant() 

and

myString.ToUpperInvariant()

Is what I'd use if ToLower and ToUpper is banned. 如果ToLower和ToUpper被禁止,我会使用它。 Also check out The Turkey Test for why it's better to use the invariants. 另请参阅土耳其测试,了解为什么最好使用不变量。

or 要么

You could create a function that will loop through the chars, adding to the ASCII values. 您可以创建一个循环字符的函数,添加ASCII值。 If you can find out the difference between the lower case and upper case chars ASCII indexes. 如果你能找出小写字母和大写字母ASCII索引之间的区别。

I tried a few different things before I realized you had 'Most efficient' in your question :) 在我意识到你的问题中“效率最高”之前,我尝试了一些不同的东西:)

Anyway, this will work and (on my machine/with limited testing) it appears to perform the same as .ToLower(). 无论如何,这将工作和(在我的机器上/有限的测试)它似乎执行与.ToLower()相同。

Dim lower1 As String = StrConv(myStr, VbStrConv.Lowercase)

I ran it 100,000 times each way and the results were nearly identical 我单程跑了10万次,结果几乎相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM