Show string in proper case

image_pdfimage_print
   
   

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:	{0}", s);
   
        string t = StringEx.ProperCase(s);
        Console.WriteLine("ProperCase:	{0}", t);
    }
}

   
    
     


This entry was posted in Data Types. Bookmark the permalink.