Keren Keren - 8 months ago 39
jQuery Question

How to insert and modify string in jquery?

This is the string received:

I need to change it into this:


things need to change:

1) add layout=download&fileid=VALUE IN VARIABLE&

2) id change to fileid

I've tried using
url.substr(0, url.indexOf('conversations&'))
to teh first string before the specific string.

Then manually added,

permanentlink = url.substr(0, url.indexOf('conversations&'));

But this keeps concatnating the string.. And I'm not sure the correct way of doing this.Can someone help?


Try replacing it using regex :

var url = '' + '&layout=download';
var newValue = 12222;
var newStr = url.replace(/id=/, 'fileid=' + newValue );
// remove this if doesnt want to replace &
var againNewStr = newStr.replace(/&/g, '&');