I'm using Flex 4. I'm driving myself crazy. Why won't the following work?
//开发者_如何学运维 in my Application tag:
creationComplete="replaceMe(event)"
// in my script block:
public function replaceMe(event:Event):void{
var str:String = "She sells seashells by the seashore.";
var pattern:RegExp = /sh/gi;
str.replace(pattern, "sch");
test.text = str;
}
my text area (id="test") says "She sells seashells by the seashore."... it should say "sche sells seaschells by the seaschore."
Because Strings are immutable objects. So, str.replace()
just returns new string, without modifying str
. Try
str = str.replace(pattern, "sch")
Assign the new string value back to the old string like so:
str = str.replace(pattern, "sch");
Edit: Dzmitry answered first. =P
精彩评论