explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

String.replace to remove values

Leave a comment

Note to self:

Task:

convert string value “12-Sep-1965” to “12Sep1965”.

Solution:

var d0:String = "12-Sep-1965";
var output:String = d0.replace( /-/g, "" );

Common Mistake:

Omitting the “replace with” parameter in the API such as:

var d0:String = "12-Sep-1965";
var output:String = d0.replace( /-/g );
trace(output); // = 12undefinedSepundefined1965

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s