开发者

String Search Replace AS3

I have a bit of text

"this is the text want I want to do is replace the text, I have just added another is for good measure"

This is stored as a standard string but I want to turn this into html and add css classes like, in this example wrapping around the word "is";

"this is the text want I want to do开发者_运维百科 is replace the text, I have just added another is for good measure"

Any ideas how I can do this in as3?


The easiest way would be to use String.replace(). Like this:

var html:String = "This is a test";
html.replace(/is/g, "<b>is</b>");

You will probably want to get a little more advanced than that (notice the problem with case) See the Flex documentation on it here: http://livedocs.adobe.com/flex/3/html/help.html?content=09_Working_with_Strings_09.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜