Keren Keren - 1 year ago 83
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?

Answer Source

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, '&');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download