How to delete part of a string in actionscript?

11,086

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.

Share:
11,086
Rella
Author by

Rella

Hi! sorry - I am C/C++ noobe, and I am reading a book=)

Updated on June 04, 2022

Comments

  • Rella
    Rella about 2 years

    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?

  • Lance
    Lance over 14 years
    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.