user3109009 user3109009 - 1 year ago 152
Javascript Question

Javascript replace all "%20" with a space

Is there a way to replace every "%20" with a space using JavaScript. I know how to replace a single "%20" with a space but how do I replace all of them?

var str = "Passwords%20do%20not%20match";
var replaced = str.replace("%20", " "); // "Passwords do%20not%20match"

Answer Source

Check this out: Replacing all occurrences of a string in javascript?

Short answer:

str.replace(/%20/g, " ");

EDIT: In this case you could also do the following:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download