, .
public static string UnCamelCase(string str)
{
return Regex.Replace(str, "([a-z])([A-Z])", "$1 $2");
}
( , , .)
, , ( )
private static Regex _unCamelRegex = new Regex("([a-z])([A-Z])", RegexOptions.Compiled);
public static string UnCamelCase(string str)
{
return _unCamelRegex.Replace(str, "$1 $2");
}
, ( , HTTPRequest):
private static Regex _unCamelRegex1 = new Regex("([a-z])([A-Z])", RegexOptions.Compiled);
private static Regex _unCamelRegex2 = new Regex("([A-Z]+)([A-Z])([a-z])", RegexOptions.Compiled);
public static string UnCamelCase(string str)
{
return _unCamelRegex2.Replace(_unCamelRegex1.Replace(str, "$1 $2"), "$1 $2$3");
}
HTTPRequestFOOBarGork HTTP Request FOO Bar Gork
, OPs ( "start at 1 skip the > 0 check" ) ( Regex). , Regex. 2 ( FooBarGork):
: 00: 00: 00.80
Regex: 00: 00: 06.71
, , . OPs ( , ), :
public static string UnCamelCaseIterative(string str)
{
if (String.IsNullOrEmpty(str))
return str;
StringBuilder sb = new StringBuilder(str[0].ToString());
for (int i = 1; i < str.Length; i++)
{
if (char.IsUpper(str, i))
sb.Append(" ");
sb.Append(str[i]);
}
return sb.ToString();
}