2

How do i convert the string;

var s='uploads\product\picture\20Duleek_Lime_Green1.jpg';

into

'uploads/product/picture/20Duleek_Lime_Green1.jpg';

The standard javascript function replace doesnt seem to work.

var s='uploads\product\picture\20Duleek_Lime_Green1.jpg';

strReplace = s.replace('\\', '//');

alert(strReplace);
4
  • 1
    Use .replace(), not .replaceAll() Commented Jun 26, 2012 at 16:03
  • @ianpgall, well that is partially right, if you did that, it would only replace the first instance. Commented Jun 26, 2012 at 16:11
  • sorry i ment "replace" and not replaceAll was using that to test another function. Commented Jun 26, 2012 at 16:23
  • @epascarello crap, i guess i'm mixing up .replace() methods between languages. sorry, you're right! Commented Jun 26, 2012 at 16:29

2 Answers 2

4

There is no replaceAll in JavaScript, use a regular expression with a global flag.

var s='uploads\\product\\picture\\20Duleek_Lime_Green1.jpg';
var strReplace = s.replace(/\\/g, '/');
alert(strReplace);
Sign up to request clarification or add additional context in comments.

Comments

0

There is no such function in javascript called replaceAll

You can use regex with replace() to achieve what you want to do.

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.