Click here to Skip to main content
13,147,956 members (89,672 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

27K views
2 bookmarked
Posted 4 Jun 2011

Pascal and Camel Case to Display Text Conversion

, 8 Jun 2011
Rate this:
Please Sign up or sign in to vote.
Pascal and Camel Case to display text conversion

Introduction


This is a handy function that you can use if you are using Reflection and have a property name, for example, "myPropertName" and you want it to be a label or a heading formatted like "My Property Name".


Background


Sometimes I use Reflection to create columns in basic administration functions in an application where there is no real business logic behind the objects. Things like type and status for example.


Using the code


Pretty straightforward. Just send a property name to it like myPropertyName or MyPropertyName and it will turn it into "My Property Name".


private string createDisplayText(string propertyName)
{
    StringBuilder builder = new StringBuilder();
 
    if(!string.IsNullOrEmpty(propertName))
    {
        character = char.ToUpper(propertName[0]);
        builder.Append(character)
    }
    for (int i = 1; i < propertyName.Length; i++)
    {
        char character = propertyName[i];
        if (char.IsUpper(character))
        {
            builder.Append(" ");
        }
    }
    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

Ben Kotvis
United States United States
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 415844517-Nov-16 4:49
memberMember 415844517-Nov-16 4:49 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 8 Jun 2011
Article Copyright 2011 by Ben Kotvis
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid