views:

31

answers:

2

I'm a noob to actionscript so this should be easy:

How do I delete leading characters from a string? I have a string that contains (at times) both numeric & non-numeric characters. If I want to delete all the leading 9's, how would I do that?

var testVar:String = '999998gjek74k';

I want the testVar to be 'gjek74k'.

So far, I have (though not working):

var testVar:String = '999998gjek74k';
testVar.replace(/^0/g, "");
+2  A: 

.replace doesn't modify the string. It returns the replaced string.

testVar = testVar.replace(/^\d+/, '');

(Also the pattern /^0/g is wrong, as commented by @santa).

KennyTM
+1  A: 

Assuming you are testing the variables and not multiple lines:

private var testVar = testVar.replace(/^\d*(.+)$/,"$1");
Robusto
Ahhhhh....perfect. works now.
ginius