views:

786

answers:

3

I want to replace a number with a character at runtime like this:

Input:

ask 1234 question

Result:

ask * question

What is the best way to accomplish this?

+1  A: 

You could use a regular expression.

Tomas Lycken
+3  A: 

Use a Regex to match a number and then do a string replace. Something along the lines of:

var str:String = "ask 1234 question"; // your string
var pattern:RegExp = /\d+/ ; // a regular expression that matches numbers
trace(str.replace(pattern, "*"));

Look up the flex 3.0 documentation for both String and Regex. Happy coding!

dirkgently
A: 

Thanks to everyone. I tried dirkgently answer was working well.

Thanks overcoming problem
You should mark dirkgently's answer as "the answer" by clicking the tick on the left of the post.
Richard Szalay
Good to know I've been able to help glory-grace. Thanks Richard!
dirkgently