如何删除动作脚本中的部分字符串? [英] How to delete part of a string in actionscript?

查看:24
本文介绍了如何删除动作脚本中的部分字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的字符串类似于BlaBlaBlaDDDaaa2aaa345"我想去掉它的子字符串BlaBlaBlaDDD"所以操作的结果将是一个字符串aaa2aaa345"如何用动作执行这样的事情?

So my string is something like "BlaBlaBlaDDDaaa2aaa345" I want to get rid of its sub string which is "BlaBlaBlaDDD" so the result of operation will be a string "aaa2aaa345" How to perform such thing with actionscript?

推荐答案

我只是使用 String#replace 正则表达式方法:

I'd just use the String#replace method with a regular expression:

var string:String = "BlaBlaBlaDDD12345";
var newString:String = string.replace(/[a-zA-Z]+/, ""); // "12345"

这将删除所有单词字符.如果您正在寻找更复杂的正则表达式,我会在网上搞乱Rubular 正则表达式测试器.

That would remove all word characters. If you're looking for more complex regular expressions, I'd mess around with the online Rubular regular expression tester.

这将删除所有非数字字符:

This would remove all non-digit characters:

var newString:String = string.replace(/[^\d]+/, ""); // "12345"

如果您知道要删除的确切字符串,请执行以下操作:

If you know the exact string you want to remove, then just do this:

var newString:String = string.replace("BlaBlaBlaDDD", "");

如果您有要删除的子字符串列表(数组),只需遍历它们并为每个子字符串调用 string.replace 方法.

If you have a list (array) of substrings you want to remove, just loop through them and call the string.replace method for each.

这篇关于如何删除动作脚本中的部分字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆