Advertisement
kyrathasoft

Properly Capitalize Name

May 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. //properly capitalize a proper name
  2.  
  3.     public static string ProperlyCapitalizeName(string p)
  4.     {  
  5.         string sResult = string.Empty;
  6.         string sFirst = string.Empty;
  7.         string sRemaining = string.Empty;
  8.        
  9.         p = p.Trim();
  10.         if(p.Length >= 2)
  11.         {
  12.             sFirst = p.Substring(0,1).ToUpper();
  13.             sRemaining = p.Substring(1,p.Length -1).ToLower();
  14.             sResult = sFirst + sRemaining;
  15.         }else{
  16.             if(p.Length < 1)
  17.             {
  18.                 sResult = "";
  19.             }else{
  20.                 sResult = sFirst.ToUpper();
  21.             }
  22.         }
  23.         return sResult;
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement