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
精彩评论