Capitalize a single 'char'acter in C#?
-
05-06-2021 - |
سؤال
Is there a "simple" way to capitalize a single char
-typed value?
This will work, but feels cumbersome and generally wrong:
var ch = 'a';
var cap = ("" + ch).ToUpper()[0];
cap.Dump(); // (in LINQPad) => 'A'
Notes:
- The choice of
"" + ch
overToString()
is because ReSharper yells at me for not specifying a culture with the latter ... in any case,ch.ToString().ToUpper()[0]
feels just as cumbersome. - For the sake of globalization, just "adding 32" is not an option; I do not believe there is any single
char
that turns into a surrogate-pair when capitalized.
Thanks,
المحلول
Char.ToUpper(ch)
should do the job.
نصائح أخرى
try Char.ToUpper()
var a = 'a';
a = Char.ToUpper(a);
لا تنتمي إلى StackOverflow