开发者

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

What is the best way to uppercase/lowercas开发者_StackOverflowe a string in .Net without using toUpper/toLower?


myString.ToLowerInvariant() 

and

myString.ToUpperInvariant()

Is what I'd use if ToLower and ToUpper is banned. 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. If you can find out the difference between the lower case and upper case chars ASCII indexes.


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().

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

I ran it 100,000 times each way and the results were nearly identical

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜