views:

528

answers:

1

Hello,

I'm getting a string that looks like this from a database: ~\Uploads\Tree.jpg And I would like to change it in Actionscript3 to Uploads/Tree.jpg

Any idea how I can do this in neat way?

+3  A: 

Assuming path is the string from the database, you can use this:

var newPath:String = path.replace(new RegExp("^~\\\\", "g"), "").replace(new RegExp("\\\\", "g"), "/")

If you always have the "~\" in the beginning, you can optimize it by using String.substring() instead. And if you are gonna convert many strings at once, make a reference to the regex and use that instead, so you do not create a new regex for each string.

Lillemanden