Starr Duskk
asked on
Converting string to initial caps: my_field_name
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
nepaluz,
Not quite as that returns "Myfieldname" not "MyFieldName"
Not quite as that returns "Myfieldname" not "MyFieldName"
Here is the code for you:-
Here is how to use this:-
using System.Globalization;
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();
}
Here is how to use this:-
string test = "my_field_name";
ToTitleCase(test,'_');
Add the following namespace:-using System.Globalization;
ASKER
Perfect!
Open in new window