Solved

Converting string to initial caps: my_field_name

Posted on 2012-04-10
5
862 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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