Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a part of string to lowercase in c# [duplicate]

I have a string like this LUXOR and I want to convert other letters to lowercase except first letter or the string.that meant, I want this string Luxor from above string. I can convert full string to upper or lower by using ToUpper or ToLower.but how can I do this.hope your help with this.thank you

like image 356
Chanaka Anuradh Caldera Avatar asked Apr 21 '16 12:04

Chanaka Anuradh Caldera


People also ask

How do I convert a string to lowercase in C?

tolower() function in C/C++ If the character passed is an uppercase alphabet then the tolower() function converts an uppercase alphabet to a lowercase alphabet. int tolower(int ch);

How do I make everything lowercase in a string?

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.

Can you use tolower on a string in C?

So yes, just loop through the string and convert each character to lowercase. for ( ; *p; ++p) *p = tolower(*p); seems more idiomatic.

How do I return a string to lowercase?

lower() is a built-in Python method primarily used for string handling. The . lower() method takes no arguments and returns the lowercased strings from the given string by converting each uppercase character to lowercase. If there are no uppercase characters in the given string, it returns the original string.


2 Answers

You can make use of TextInfo class that Defines text properties and behaviors, such as casing, that is specific to a writing system.

 string inString = "LUXOR".ToLower();
 TextInfo cultInfo = new CultureInfo("en-US", false).TextInfo;
 string output = cultInfo.ToTitleCase(inString);

This snippet will give you Luxor in the variable output. this can also be used to capitalize Each Words First Letter

Another option is using .SubString, for this particular scenario of having a single word input:

string inString = "LUXOR"
string outString = inString.Substring(0, 1).ToUpper() + inString.Substring(1).ToLower(); 
like image 198
sujith karivelil Avatar answered Oct 07 '22 16:10

sujith karivelil


Try This,

        string inString = "LUXOR";
        string output = inString.Substring(0, 1) + inString.Substring(1).ToLower();

        string inString2 = "HI HOW ARE YOU";
        string[] finalstring = inString2.Split(' ');

        string output2 = string.Empty;
        foreach (var item in finalstring)
        {
            if (output2 == "")
            {
                output2 = (item.ToUpper().Substring(0, 1) + item.ToLower().Substring(1));
            }
            else
            {
                output2 += " " + (item.ToUpper().Substring(0, 1) + item.ToLower().Substring(1));
            }

        }
like image 36
Prabhat Sinha Avatar answered Oct 07 '22 17:10

Prabhat Sinha