Solved

Converting string to initial caps: my_field_name

Posted on 2012-04-10
5
857 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:BobCSD
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
nepaluz,

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

Expert Comment

by:BuggyCoder
Comment Utility
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 1

Author Closing Comment

by:BobCSD
Comment Utility
Perfect!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now