[英]How to delete part of a string in actionscript?
所以我的字符串就像“BlaBlaBlaDDDaaa2aaa345”我想摆脱它的子字符串“BlaBlaBlaDDD”所以操作的结果将是一个字符串“aaa2aaa345”如何用actionscript执行这样的事情?
I'd just use the String#replace method with a regular expression: 我只是将String#replace方法与正则表达式一起使用:
var string:String = "BlaBlaBlaDDD12345";
var newString:String = string.replace(/[a-zA-Z]+/, ""); // "12345"
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.
如果你正在寻找更复杂的正则表达式 ,我会乱用在线Rubular正则表达式测试器。
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", "");
If you have a list (array) of substrings you want to remove, just loop through them and call the string.replace
method for each. 如果你有一个你要删除的子串的列表(数组),只需遍历它们并为每个子串调用
string.replace
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.