How to remove %20 from your string or How to decode your text from a variable like "Hurrah%21%20We%20have%20won%20the%20match" using java Script or jQuery?.
So Guys You Need to remove the %20 like unknown codes.
Sol:
1) If you want to remove %20 from a text like "I%20am%20a%20Student." only then you should use
var txt ="I%20am%20a%20Student."
var str = txt.replace(/%20/g," ")
console.log(str);
Output: I am a Student.
OR
simply, You can use
decodeURI(txt)
OR
decodeURIComponent(txt)
OR
unescape(txt)
2) If you want to remove %20, %2E etc from a text like "Hurrah%21%20We%20have%20won%20the%20match%2E" then you should use
var str ="Hurrah%21%20We%20have%20won%20the%20match%2E"
unescape(txt) **
OR
decodeURI(txt)
OR
decodeURIComponent(txt)
**You Should avoid use of unescape() as it was deprecated in JavaScript version 1.5.
Comments
Post a Comment