Mega Code Archive

 
Categories / C# / Data Types
 

Show string in proper case

using System; using System.Text; public class StringEx {     public static string ProperCase(string s)     {         s = s.ToLower();         string sProper = "";             char[] seps = new char[]{' '};         foreach (string ss in s.Split(seps))         {             sProper += char.ToUpper(ss[0]);             sProper +=              (ss.Substring(1, ss.Length - 1) + ' ');         }         return sProper;     } }     class MainClass {     static void Main(string[] args)     {         string s  = "tHE test";         Console.WriteLine("Initial String:\t{0}", s);             string t = StringEx.ProperCase(s);         Console.WriteLine("ProperCase:\t{0}", t);     } }