2010-11-09 129 views
0

我正在使用Flex 4.我疯狂地开车。为什么不能继续工作?正则表达式不工作... arghhhh

//在我的应用程序标签:

creationComplete="replaceMe(event)" 

//在我的脚本块:

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; 
} 

我的文字区域(ID = “测试”)说:“她在海边卖贝壳“...... 它应该说”sche在海边销售海边。“

回答

3

因为字符串是不可变的对象。所以,str.replace()只是返回新的字符串,而不修改str。尝试

str = str.replace(pattern, "sch") 
0

分配新的字符串值回旧字符串,像这样:

​​

编辑: Dzmitry回答第一。 = P