views:

75

answers:

1

I'm trying to do initial caps in actionScript with no loops but now i'm stuck. I wanted to select the first letter or every word then apply uppercase on that letter. Well I got the selection part right, but at a dead end right now, any ideas? I was trying to do this with out loops and cutting up strings.

//replaces with x cant figure out how to replace with the found result as uppercase

            public function initialcaps():void 
            {
    var pattern:RegExp=/\b[a-z]/g;
    var myString:String="yes that is my dog dancing on the stage";
    var nuString:String=myString.replace(pattern,"x");
    trace(nuString);
   }
+1  A: 

Try to use a function that returns the uppercase letter:

myString.replace(pattern, function($0){return $0.toUpperCase();})

This works at least in JavaScript.

Gumbo
Hi Gumbo, thanks for the reply. This works perfectly, it just puts up a flag for anonymous function(not a big deal). If you don't mind me asking. What is the $0? the $ doesn't seem to be in a AS3 doc's. So how is this working?
Deyon
@Deyon: `$0` is just a regular variable identifier. You could also use `match` or whatever you want. But since `replace` uses `$1`, `$2`, etc. to reference matches of groups, `$0` is a good name for the whole match.
Gumbo