开发者

Why doesn't ToUpper() return "*" when applied to "8"?

string s = "h";
s = s.ToUpper();

returns "H".

开发者_C百科
string s = "8";
s = s.ToUpper();

returns "8"

Should this not return "*"?


No, it shouldn't. ToUpper() doesn't mean WithShiftKeyOnAnInternationalASCIIKeyboard(). There isn't an uppercase 8, as 8 is a number, not a letter.

Of course, this is a gross over-simplification (being a number alone doesn't automatically make a certain character in a character set caseless), but it's likely what you're asking for anyway so I'll leave it at that.


Because there is no upper case 8.

Just because the specific keyboard you are using has a * on the same key as the 8, doesn't mean that all keyboards do. Some languages do not have upper case letter - what should ToUpper return for those?

String.ToUpper():

This method uses the casing rules of the current culture to convert each character in the current instance to its uppercase equivalent. If a character does not have an uppercase equivalent, it is included unchanged in the returned string.


The real answer is because the TextInfo associated with the CultureInfo for en-US does not define "*" as the uppercase of "8".

It may be possible to extend that TextInfo, override toUpper(), and have it work like you wish.


  1. Numbers don't have uppercases.
  2. if you would use the function ToUpper() to following Text: "there are 8 buildings"
    What result would you like to have? "THERE ARE 8 BUILDINGS" or "THERE ARE * BUILDINGS"
  3. the Keyboardlayout is localized e.g. on german keyboards there is a ( at the 8 key


Just because you press shift 8 to get a * doesnt make it an uppercase value, it only applies for a-z characters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜