1

I have written a JSFiddle with the expected output and output my code is currently doing. The two different values must be parsed as either a colon or a semi-colon as I need to know what one line to parse in php is.

var data = "key=update.repositories&value=xime+mcsg+mcsg-maps&key=server.minPlayersToStart&value=12";
data.replace(/&v/g, ":v");
data.replace(/&k/g, ";k");

$(".encData").text(data);

Fiddle found here: http://jsfiddle.net/RS6xC/1/

kpwn243
  • 13
  • 4

2 Answers2

1

string.replace() doesn't change the original variable, it returns a new value.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

So you need to reassign the returned value of the replace() method to the original variable, such as like this:

var data = "key=update.repositories&value=xime+mcsg+mcsg-maps&key=server.minPlayersToStart&value=12";
data = data.replace(/&v/g, ":v");
data = data.replace(/&k/g, ";k");
$(".encData").text(data);
Stu Blair
  • 1,323
  • 15
  • 24
0

.replace returns a new string, it does not modify the existing string.

Use:

data=data.replace(/&v/g, ":v");
data=data.replace(/&k/g, ";k");
John Stimac
  • 5,335
  • 8
  • 40
  • 60