Solved

Converting string to initial caps: my_field_name

Posted on 2012-04-10
5
865 Views
Last Modified: 2012-04-10
I'm retrieving a fieldname from a table and want to convert it to initial caps and remove the underscore like so:

my_field_name
to
MyFieldName

How do I do that? I'm using vb.net but C# is fine if that is all you know.

thanks!
0
Comment
Question by:Starr Duskk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 37829334
Try this function:
    Private Function ConvertFieldName(Name As String) As String
        Return StrConv(Name.Replace("_", " "), VbStrConv.ProperCase).Replace(" ", String.Empty)
    End Function

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37829403
or even
Private Function ConvertFieldName(Name As String) As String
    Return StrConv(Name.Replace("_", String.Empty), VbStrConv.ProperCase)
End Function

Open in new window

0
 
LVL 38

Expert Comment

by:PaulHews
ID: 37829421
nepaluz,

Not quite as that returns "Myfieldname" not "MyFieldName"
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37829462
Here is the code for you:-

private static string ToTitleCase(string text, char splitCharacter)
        {
            var txtInfo = new CultureInfo("en-US", false).TextInfo;
            var builder = new StringBuilder();

            text.Split(splitCharacter).ToList().ForEach(s => builder.Append(txtInfo.ToTitleCase(s)));
            return builder.ToString();
        }

Open in new window


Here is how to use this:-

string test = "my_field_name";
ToTitleCase(test,'_');

Open in new window

Add the following namespace:-
using System.Globalization;
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 37829583
Perfect!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question