Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Pascal and Camel Case to Display Text Conversion

0.00/5 (No votes)
14 Jun 2011 1  
This version treats the input string as an indexed string. The code is a little shorter.private string createDisplayText(string propertyName){ if (String.IsNullOrEmpty(propertyName)) { return String.Empty; } StringBuilder builder = new StringBuilder(); ...

This version treats the input string as an indexed string. The code is a little shorter.


C#
private string createDisplayText(string propertyName)
{
    if (String.IsNullOrEmpty(propertyName))
    {
        return String.Empty;
    }

    StringBuilder builder = new StringBuilder();
    builder.Append(char.ToUpper(propertyName[0]));

    for (int i = 1; i < propertyName.Length; ++i)
    {
        builder.Append((char.IsUpper(propertyName, i)) ? " " + 
                propertyName[i].ToString() : propertyName[i].ToString());
    }
    return builder.ToString();
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here