Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Fixed the non working old code to make it run
Source Link
Vinod Srivastav
  • 4.3k
  • 1
  • 34
  • 45
public string FirstLetterToUpper(string str) { if (str == null) return null; if (str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); return str.ToUpper(); } 

Old answer: This makes everythis can also be written as

public string ToTitleCase(string str) { var firstword = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.Split(' ')[0].ToLower()); str = str.Replace(str.Split(' ')[0],firstword); return str; } 

Where it picks up the first letterword and converts it to uppertitle case then replaces it in the input string.

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string FirstLetterToUpper(string str) { if (str == null) return null; if (str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); return str.ToUpper(); } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string FirstLetterToUpper(string str) { if (str == null) return null; if (str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); return str.ToUpper(); } 

this can also be written as

public string ToTitleCase(string str) { var firstword = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.Split(' ')[0].ToLower()); str = str.Replace(str.Split(' ')[0],firstword); return str; } 

Where it picks up the first word and converts it to title case then replaces it in the input string.

deleted 46 characters in body
Source Link
Diego
  • 20.3k
  • 5
  • 34
  • 46
public string FirstLetterToUpper(string str) { if (str !=== null) {   return null;  if (str.Length > 1)   return char.ToUpper(str[0]) + str.Substring(1);  else   return str.ToUpper(); } return str; } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string FirstLetterToUpper(string str) { if (str != null) {  if(str.Length > 1)   return char.ToUpper(str[0]) + str.Substring(1);  else   return str.ToUpper(); } return str; } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string FirstLetterToUpper(string str) { if (str == null)   return null;  if (str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); return str.ToUpper(); } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
added 349 characters in body
Source Link
Diego
  • 20.3k
  • 5
  • 34
  • 46
public string FirstLetterToUpper(string str) { if (str != null) { if(str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); else return str.ToUpper(); } return str; } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
public string FirstLetterToUpper(string str) { if (str != null) { if(str.Length > 1) return char.ToUpper(str[0]) + str.Substring(1); else return str.ToUpper(); } return str; } 

Old answer: This makes every first letter to upper case

public string ToTitleCase(string str) { return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str.ToLower()); } 
Source Link
Diego
  • 20.3k
  • 5
  • 34
  • 46
Loading