Converts to Camel casing. "FooBar" becomes "fooBar" "Foobar becomes "foobar" - CSharp System

CSharp examples for System:String Convert

Description

Converts to Camel casing. "FooBar" becomes "fooBar" "Foobar becomes "foobar"

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.IO;//from   w w w .  jav a2s .c o m
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        #if !PORTABLE
        /// <summary>
        /// Converts to Camel casing.
        /// "FooBar" becomes "fooBar"
        /// "Foobar becomes "foobar"
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string ToCamelCase(this String source, CultureInfo cultureInfo)
        {
            if (String.IsNullOrEmpty(source))
            {
                return source;
            }
            else if (source.Length == 1)
            {
                return source.ToLower(cultureInfo);
            }
            else
            {
                return source[0].ToString().ToLower(cultureInfo) + String.Join("", source.Substring(1));
            }
        }
        #endif

        /// <summary>
        /// Converts to Camel casing.
        /// "FooBar" becomes "fooBar"
        /// "Foobar becomes "foobar"
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string ToCamelCase(this String source)
        {
            if (String.IsNullOrEmpty(source))
            {
                return source;
            }
            else if (source.Length == 1)
            {
                return source.ToLower();
            }
            else
            {
                return source[0].ToString().ToLower() + String.Join("", source.Substring(1));    
            }
        }
}

Related Tutorials