开发者

splitting a string in as3

i have several strings that look like this:

conta开发者_如何学CctBtn, programBtn, cartBtn. How can i split these strings so that the "btn" gets discarted, so i keep contact, program, cart. How would i achieve this?


The String class has a replace method:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html


Check out the Replace() Section of the ActionScript 3.0 Documentation.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#match%28%29

var yourString:String = “contactBtn”
yourString= yourString.split(“Btn”).join(“”);
trace(yourString); 

// Output : yourString = "contact"

You would just have to iterate through all of your buttons.


You can also use RegExp :

trace(/.+(?=btn$)/gi.exec("foobtn"));//foo
trace(/.+(?=btn$)/gi.exec("fooBTN"));//foo
trace(/.+(?=btn$)/gi.exec("barbtn"));//bar
trace(/.+(?=btn$)/gi.exec("bar"));//null
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜