Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

returns "H".

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

returns "8"

Should this not return "*"?

like image 618
newkid91 Avatar asked Jun 09 '11 19:06

newkid91


People also ask

How does ToUpper work in C#?

In C#, ToUpper() is a string method. It converts every characters to uppercase (if there is an uppercase version). If a character does not have an uppercase equivalent, it remains unchanged. For example, special symbols remain unchanged.

Does ToUpper work on char?

In C#, the Toupper() function of the char class converts a character into uppercase. In the case that we will be discussing, only the first character of the string needs to be converted to uppercase; the rest of the string will stay as it is.

What is ToUpper in Visual Basic?

ToUpper converts all characters to uppercase characters. It causes a copy to be made of the VB.NET String, which is returned. Here We look at ToUpper and its behavior. This console program shows the result of ToUpper on the input String "abc123".

Why would it be useful to include the ToUpper method in a comparison?

The ToUpper method is often used to convert a string to uppercase so that it can be used in a case-insensitive comparison. A better method to perform case-insensitive comparison is to call a string comparison method that has a StringComparison parameter whose value you set to StringComparison.


1 Answers

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.

like image 98
BoltClock Avatar answered Oct 16 '22 20:10

BoltClock