Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

String Extender Functions

RSS
Modified on Sat, Jun 05, 2010, 2:10 PM by Administrator Categorized as ┬ĚNet Framework
{copytext|div1}
//------------------------------------------------------------------------------
public static string ToProperCase(this string text)
{
    string result = "";
    char apos = (char)39;

    for (int i = 0; i < text.Length; i++)
    {
        string s = text[i].ToString();
        if (i == 0 || (!char.IsLetter(text[i - 1]) & text[i-1] != apos))
            result += s.ToUpper();
        else
            result += s;
    }
    return result;
}
//------------------------------------------------------------------------------
/// <summary>
/// Takes a Proper-Cased variable name and adds a space before each
/// capital letter.
/// </summary>
public static string AddSpaces(this string text)
{
    string result = "";
    for (int i = 0; i < text.Length; i++)
    {
        if (i > 0 && char.IsUpper(text[i]))
            result += " ";
        result += text.Substring(i, 1);
    }
    return result;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2014, Patrick Jasinski.