0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.