Example 1 : - public static string ToTitleCase(string str)
- {
- string result = str;
- if (!string.IsNullOrEmpty(str))
- {
- var words = str.Split(' ');
- for (int index = 0; index < words.Length; index++)
- {
- var s = words[index];
- if (s.Length > 0)
- {
- words[index] = s[0].ToString().ToUpper() + s.Substring(1);
- }
- }
- result = string.Join(" ", words);
- }
- return result;
- }
Input : String strR = ToTitleCase("c sharp corner");
output: C Sharp Corner
Example 2 :
- public static string FirstCharToUpper(string input)
- {
- if (String.IsNullOrEmpty(input))
- throw new ArgumentException("Error !");
- return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());
- }
Input : String strR = FirstCharToUpper("c sharp corner");
output: C Sharp Corner