-1

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 
billah77
  • 196
  • 1
  • 1
  • 13

6 Answers6

1

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.com/jsref/jsref_decodeuri.asp

Community
  • 1
  • 1
Merlin Denker
  • 1,380
  • 10
  • 15
0

If theString has your original string, try:

theString = theString.replace(/%20/g, "")
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
0

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% !

0

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.

Vedant Terkar
  • 4,553
  • 8
  • 36
  • 62
0

try this function :

function Replace(str) {
  var del = new RegExp('%20');
  str.match(del);
}
angel
  • 322
  • 1
  • 7
0

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.com/    ?key=value`;
string.replace(/\s+/g, "");

This will give you: https://example.com/?key=value;

Amir Hassan Azimi
  • 9,180
  • 5
  • 32
  • 43