private static readonly char[] Delimeters = {' '}; public static string ToCamelCase(string input) { var sb = new StringBuilder(); input = input.ToLowerInvariant(); var split = input.Split(Delimeters, StringSplitOptions.RemoveEmptyEntries); foreach (var s in split) { for(int i = 0; i < s.Length; i++) { var c = s[i]; sb.Append(i == 0 ? char.ToUpperInvariant(c) : c); } } return sb.ToString().Trim(); } public static string FromCamelCaseToNormal(string input) { var sb = new StringBuilder(); foreach (var c in input) { if (char.IsUpper(c) || char.IsDigit(c)) sb.Append(" "); sb.Append(c); } return sb.ToString().Trim(); }
Friday, October 7, 2016
Transform string to and from camel case.
Small piece of code to transform a string to and from camel case form. For anyone who find that kind of things useful.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment