Hi how can i remove empty space in the URL using javascript: here how it looks like
stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&sealA=255146-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&terminalB=916876-010&sealB=255146-000
This is what i want:
stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000&sealA=255146-000&terminalB=916876-010&sealB=255146-000
Hi how can i remove empty space in the URL using javascript: here how it looks like
stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&sealA=255146-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&terminalB=916876-010&sealB=255146-000
This is what i want:
stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000&sealA=255146-000&terminalB=916876-010&sealB=255146-000
url = url.replace(/%20/g, '');
– Aamir Afridi
Commented
May 16, 2014 at 13:21
Just decode the url, use the replace function to eliminate the whitespaces and then encode it again.
function removeSpaces(url) {
return encodeURIComponent(decodeURIComponent(url).replace(/\s+/g, ''));
}
JS replace-Function to eliminate whitespaces: How to remove spaces from a string using JavaScript? Javascript decode and encode URI: http://www.w3schools./jsref/jsref_decodeuri.asp
If theString
has your original string, try:
theString = theString.replace(/%20/g, "")
you can simply replace the substring you want ("%20") with nothing (or ""). Try something like this:
var str = "stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&sealA=255146-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&terminalB=916876-010&sealB=255146-000"
var res = str.replace(/%20/g, "");
Hope it helps.
The idea is just the 1%, now go make the 99% !
try this function :
function Replace(str) {
var del = new RegExp('%20');
str.match(del);
}
This Might Help you:
function doIt(){
var url="stockcode=1ECN0010-000&quantity=100&wiretype=SAVSS0.85B&wirelength=0.455&terminalA=916189-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&sealA=255146-000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&terminalB=916876-010&sealB=255146-000";
var str=url.toString();
str=str.split("%20").join("");
return str;
}
Here is Working Fiddle.
You will need to treat the URL as string and remove the whitespace inside that string using your programming language.
For example, if you use JavaScript to remove the whitespace from the URL you can do this:
let string = `https://example./ ?key=value`;
string.replace(/\s+/g, "");
This will give you: https://example./?key=value;