Posted By

lance on 07/20/12


Tagged


Versions (?)

Change person's name to upper and lower


 / Published in: C#
 

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

  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  

You need to login to post a comment.