开发者

regexp not working...arghhhh

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜