Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lowercase a string except for first character with C#

Tags:

How do convert a string to lowercase except for the first character? Can this be completed with LINQ?

Thanks

like image 821
Ricky Avatar asked Dec 13 '10 09:12

Ricky


People also ask

How do I convert a string to lowercase except first letter?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.

How do I return a string to lowercase?

lower() Return value lower() method returns the lowercase string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns the original string.

How do you make all letters lowercase in c?

In C, the tolower() function is used to convert uppercase letters to lowercase. When an uppercase letter is passed into the tolower() function, it converts it into lowercase. However, when a lowercase letter is passed into the tolower() function, it returns the same letter. Note: In order to use this function, ctype.

Which function is used for converting string into lowercase in c?

C tolower() The tolower() function takes an uppercase alphabet and convert it to a lowercase character. If the arguments passed to the tolower() function is other than an uppercase alphabet, it returns the same character that is passed to the function. It is defined in ctype. h header file.


1 Answers

If you only have one word in the string, you can use TextInfo.ToTitleCase. No need to use Linq.

As @Guffa noted:

This will convert any string to title case, so, "hello world" and "HELLO WORLD" would both be converted to "Hello World".


To achieve exectly what you asked (convert all characters to lower, except the first one), you can do the following:

string mostLower = myString.Substring(0, 1) + myString.Substring(1).ToLower();
like image 103
Oded Avatar answered Sep 28 '22 04:09

Oded