Mega Code Archive

 
Categories / C# / Data Types
 

Proper Case

using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Net.Mail; using System.Diagnostics; namespace QueueManagerHelper {     public class UtilityHelper     {         public static string ProperCase(string Source)         {             string originalSource = Source;             try             {                 StringBuilder sb = new System.Text.StringBuilder();                 bool emptyBefore = true;                 foreach (char ch in Source)                 {                     char chThis = ch;                     if (Char.IsWhiteSpace(chThis))                         emptyBefore = true;                     else                     {                         if (Char.IsLetter(chThis) && emptyBefore)                             chThis = Char.ToUpper(chThis);                         else                             chThis = Char.ToLower(chThis);                         emptyBefore = false;                     }                     sb.Append(chThis);                 }                 return sb.ToString();             }             catch (Exception)             {                 return originalSource;             }         }     } }