C # use capital letters

Possible duplicate:
How to make first capital letters in C #

I'm trying to make amends for the first word in a sentence, this is what it is, but it does not work. Thanks in advance for any help.

char.ToUpper(sentence[0]) + sentence.Substring(1) 
+6
source share
2 answers

JaredPar's solution is right, but I would also like to point you to the TextInfo class. ToTitleCase () will use the first letter and convert the remainder to lowercase.

  string s = "heLLo"; var t = new CultureInfo("en-US", false).TextInfo; s = t.ToTitleCase(s); //prints "Hello" 
+9
source

It looks like you're just trying to smooth out the first character of a string value. If so, then your code will be fine, but you need to assign a new line to the sentence value.

 sentence = char.ToUpper(sentence[0]) + sentence.Substring(1) 

A string in .Net is immutable, and so every operation that changes the value of string produces a new value. It will not change the original meaning in place. Therefore, to see the result of a change, you must assign it to a variable.

+4
source

Source: https://habr.com/ru/post/911608/


All Articles