I have the input string "textfile\foldername\text.txt"
Now i need to convert given string to:

textfile/foldername/text.txt

I went through string.replace(oldchar, newchar) methods, but i actually couldnt remove the " and \ characters from the string. Need help

Recommended Answers

All 2 Replies

Try this:

//...

string = string.replace('\\', '/'); // replace \ with /
string = string.replace('\"', ' '); // replace " with space
string = string.trim(); // remove leading and trailing spaces

//...

it would also be good practice to try and understand why you need escape characters there, and why you can't just replace the \ and " chars.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.