String To Camel Case - CSharp System

CSharp examples for System:String Case

Description

String To Camel Case

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w  w  .j av  a2  s.c o m

public class Main{
        public static string ToCamelCase(this string text)
        {
            text = string.Join(" ", from s in text.Split(' ') select char.ToUpper(s[0]) + s.Substring(1));
            while (text.Contains('_'))
            {
                int index = text.IndexOf('_');
                text = text.Substring(0, index) + char.ToUpper(text[index + 1]) + text.Substring(index + 2);
            }
            return text;
        }
}

Related Tutorials