CSharp examples for System:String Case
Accepts a string like "ArrowRotateClockwise" and returns "arrow_rotate_clockwise.png".
/*//from ww w . j av a 2s .c om * @version : 2.5.0 * @author : Ext.NET, Inc. http://www.ext.net/ * @date : 2014-10-20 * @copyright : Copyright (c) 2008-2014, Ext.NET, Inc. (http://www.ext.net/). All rights reserved. * @license : See license.txt and http://www.ext.net/license/. * @website : http://www.ext.net/ */ using System.Web.UI; using System.Web; using System.Text.RegularExpressions; using System.Text; using System.Security.Cryptography; using System.Globalization; using System.ComponentModel; using System.Collections.Generic; using System.Collections; using System; public class Main{ /// <summary> /// Accepts a string like "ArrowRotateClockwise" and returns "arrow_rotate_clockwise.png". /// </summary> public static string ToCharacterSeparatedFileName(this string name, char separator, string extension) { if (name.IsEmpty()) { return name; } MatchCollection match = Regex.Matches(name, @"([A-Z]+)[a-z]*|\d{1,}[a-z]{0,}"); string temp = ""; for (int i = 0; i < match.Count; i++) { if (i != 0) { temp += separator; } temp += match[i].ToString().ToLowerInvariant(); } string format = (string.IsNullOrEmpty(extension)) ? "{0}{1}" : "{0}.{1}"; return string.Format(format, temp, extension); } /// <summary> /// Determine is the string is null or empty. /// </summary> /// <param name="text"></param> /// <returns></returns> public static bool IsEmpty(this string text) { return string.IsNullOrEmpty(text); } }