Daniel Daniel - 1 year ago 75
Javascript Question

how to add more text to a string before a special char

I would like to modify a string using jQuery as following:

Existing value:


New value:

How can I do it? Maybe with the

Answer Source

You can use the replace() function on your string. In this case you could replace the .png with _notold.png:

var foo = 'myimage_one.png';
var bar = foo.replace('.png', '_notold.png');

Also note that this is a native JS method and has nothing to do with jQuery

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