3

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?

Rella
  • 65,003
  • 109
  • 363
  • 636

1 Answers1

9

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.

Lance
  • 75,200
  • 93
  • 289
  • 503
  • 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. – Lance Mar 20 '10 at 01:56