Convert To Camel case

c# Code : Convert to camel case

public static class Program
static void Main(string[] args)
Console.WriteLine(  ToCamelCase(“hi this is Cool”));

public static string ToCamelCase(this string input)
string[] words = input.Split(‘ ‘);
StringBuilder sb = new StringBuilder();
foreach (string s in words)
string firstLetter = s.Substring(0, 1);
string rest = s.Substring(1, s.Length – 1);
sb.Append(firstLetter.ToUpper() + rest);
sb.Append(” “);

return sb.ToString().Substring(0, sb.ToString().Length – 1);

4 thoughts on “Convert To Camel case

  1. You can also do it with a one-liner:

    private string ToCamelCase(string phrase)
    return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(phrase.ToLowerInvariant().Trim()).Replace(“_”, “”);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s