Show string in proper case in CSharp
Description
The following code shows how to show string in proper case.
Example
using System;//w w w .j ava2 s.co m
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);
}
}
The code above generates the following result.