ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToCamelCase

Convert a String into CamelCase

Source

public static string ToCamelCase(this string the_string)
{
    if (the_string == null || the_string.Length < 2)
        return the_string;

    string[] words = the_string.Split(
        new char[] { },
        StringSplitOptions.RemoveEmptyEntries);

    string result = words[0].ToLower();
    for (int i = 1; i < words.Length; i++)
    {
        result +=
            words[i].Substring(0, 1).ToUpper() +
            words[i].Substring(1);
    }

    return result;
}

Example

Var str="this is Sampel String".ToCamelCase();

Author: Anonymous

Submitted on: 27 apr. 2016

Language: C#

Type: String

Views: 17262