C# uppercase lowercase

ToUpper() method of string changes the string to uppercase. ToLower() method of string changes the string to lowercase.

string str = "endmemo c# tutorial";
str.ToUpper(); //ENDMEMO C# TUTORIAL
str.ToLower(); //endmemo c# tutorial
char c = 't';
c.ToString().ToUpper(); //T
char c2 = 'T';
c2.ToString().ToLower(); //t

Following function turns the first letter a sentence to uppercase.
public static string UppercaseFirst(string s)
{
string str = "";
str += s[0].ToString().ToUpper();
str += s.Substring(1);
return str;
}

Following function turns all first letters of the words inside a sentence to uppercase.
public static string UppercaseAllFirst(string s)
{
string str = "";
string[] arr = s.Split(' ');
if (arr.Length == 1)
{
str += s[0].ToString().ToUpper();
str += s.Substring(1);
}
else
{
foreach (string wd in arr)
{
str += wd[0].ToString().ToUpper();
str += wd.Substring(1) + " ";
}
str.TrimEnd();
}
return str;
}


endmemo.com © 2017  Terms of Use | Home