Click here to Skip to main content
11,712,241 members (69,846 online)
Click here to Skip to main content

Tagged as

Pascal and Camel Case to Display Text Conversion

, 14 Jun 2011 CPOL 3.9K 1
Rate this:
Please Sign up or sign in to vote.
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.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Steve Roberson
Software Developer (Senior) SouthData, Inc.
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralI had tried that and propertyName[i] was returning me the de... Pin
Steve Roberson16-Jun-11 3:17
memberSteve Roberson16-Jun-11 3:17 
GeneralYou can remove the ToString() calls if you replace the " " w... Pin
kiswa0016-Jun-11 2:23
memberkiswa0016-Jun-11 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 14 Jun 2011
Article Copyright 2011 by Steve Roberson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid