views:

204

answers:

1

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?

+1  A: 

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"

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", "");

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

viatropos
ups - missunderstending accured...
Blender
do you know what you want to remove? Is it always going to be "BlaBlaBlaDDD"? If you can define a pattern for it, regular expressions should do the trick. Elaborate more on the patterns you're trying to match to see if I can help you.
viatropos