Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Pascal and Camel Case to Display Text Conversion

, 14 Jun 2011
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

United States United States
No Biography provided

Comments and Discussions

 
GeneralI had tried that and propertyName[i] was returning me the de... PinmemberSteve Roberson16-Jun-11 3:17 
GeneralYou can remove the ToString() calls if you replace the " " w... Pinmemberkiswa0016-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 | Mobile
Web02 | 2.8.140827.1 | Last Updated 14 Jun 2011
Article Copyright 2011 by Steve Roberson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid