Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Created November 19, 2014 12:07
Show Gist options
  • Save mattcanty/e4c193be089c1b018e86 to your computer and use it in GitHub Desktop.
Save mattcanty/e4c193be089c1b018e86 to your computer and use it in GitHub Desktop.
Turn "SomethingLikeThis" into "Something Like This"
using System.Text.RegularExpressions;
namespace Spin.TradingServices.Common.Library.Extensions
{
public static class StringExtensions
{
private const string CamelToSpacedRegexString =
@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])";
private static readonly Regex CamelToSpacedRegex = new Regex(CamelToSpacedRegexString,
RegexOptions.IgnorePatternWhitespace);
public static string FromCamelToSpaced(this string camelString)
{
return CamelToSpacedRegex.Replace(camelString, " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment