When doing case-insensitive comparisons, is it more efficient to convert the string to upper case or lower case? Does it even matter?
It is suggested in this SO post that C# is more efficient with ToUpper because "Microsoft optimized it that way." But I've also read this argument that converting ToLower vs. ToUpper depends on what your strings contain more of, and that typically strings contain more lower case characters which makes ToLower more efficient.
In particular, I would like to know:
- Is there a way to optimize ToUpper or ToLower such that one is faster than the other?
- Is it faster to do a case-insensitive comparison between upper or lower case strings, and why?
- Are there any programming environments (eg. C, C#, Python, whatever) where one case is clearly better than the other, and why?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…