Wednesday, September 19, 2012

Camel Case to Spaces AS3

// using regex

var camelCase:String = "CamelCaseIsSexy";
function camelCase2human(s:String):String {
     var myRegExp:RegExp = /(^[a-z]|[A-Z0-9])[a-z]*/g;
     var catches:Object = s.match(myRegExp);
     var humanReadable:String = "";
     for( var j:String in catches ) {
          humanReadable += catches[j] + " ";
     }
     return humanReadable;
}

trace( camelCase2human(camelCase);

2 comments:

Unknown said...

public static function camelCase2human(s:String):String
{
var myRegExp:RegExp = /(^[a-z]|[A-Z0-9])[a-z]*/g;
var catches:Array = s.match(myRegExp);
var humanReadable:String = "";
return catches.join(" ");
}

Oliver said...

Nice! Thank-you!