CSharp examples for System:String Convert
Remove any underscores or dashes and convert a string into camel casing.
using System.Text.RegularExpressions; using System.Text; using System.Globalization; using System;/*from www . jav a2 s.c o m*/ public class Main{ /// <summary> /// Remove any underscores or dashes and convert a string into camel casing. /// </summary> /// <param name="value"></param> /// <returns></returns> /// <example>StringHelper.Camelize("data_rate"); //"dataRate"</example> /// <example>StringHelper.Camelize("background-color"); //"backgroundColor"</example> /// <example>StringHelper.Camelize("-webkit-something"); //"WebkitSomething"</example> /// <example>StringHelper.Camelize("_car_speed"); //"CarSpeed"</example> /// <example>StringHelper.Camelize("yes_we_can"); //"yesWeCan"</example> // Inspired by http://stringjs.com/#methods/camelize public static string Camelize(string value) { if (String.IsNullOrWhiteSpace(value)) { return value; } return Regex.Replace(value, @"[-_]\p{L}", m => m.ToString().ToUpper(CultureInfo.CurrentCulture)).Replace("-", "").Replace("_", ""); } }