Change person's name to upper and lower


/ Published in: C#
Save to your folder(s)

Makes first letter upper and the rest lower except for names like Mcsomething


Copy this code and paste it in your HTML
  1. internal string TurnFirstToUpperAndRestLower(string input)
  2. {
  3. if (!string.IsNullOrEmpty(input))
  4. {
  5. string theRest = null;
  6. string first = string.IsNullOrEmpty(input.Substring(0, 1)) ? null : input.Substring(0, 1).ToUpper();
  7. if (input.Length > 1 && input.Substring(0, 1).ToUpper() != "M" && input.Substring(1, 1).ToUpper() != "C")
  8. {
  9. theRest = string.IsNullOrEmpty(input.Substring(1, input.Length - 1)) ? null : input.Substring(1, input.Length - 1).ToLower();
  10. }
  11. else
  12. {
  13. theRest = input.Length > 1 ? input.Substring(1, input.Length - 1) : null;
  14. }
  15. return first + theRest;
  16. }
  17. else
  18. {
  19. return null;
  20. }
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.