开发者

regexp not working...arghhhh

开发者 https://www.devze.com 2023-01-23 22:29 出处:网络
I\'m using Flex 4. I\'m driving myself crazy. Why won\'t the following work? //开发者_如何学运维 in my Application tag:

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

精彩评论

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