Asim Naseer
Asim Naseer

Reputation: 143

Removing a replacing character using jquery

In a variable I have a string value Agriculture & Development. I want to remove Whitespaces and character '&' from the string Agriculture & Development so that it looks like Agriculture_Development using jquery or javascript.

Upvotes: 0

Views: 163

Answers (2)

KooiInc
KooiInc

Reputation: 122906

No need for jquery here, plain js will do:

var nwstr = 'Agriculture & Development'
                .replace(/\s+/g,'')
                .replace(/\&/,'_');
//=> Agriculture_Development

Now go and figure things out yourself

Upvotes: 4

TRR
TRR

Reputation: 1643

var str = "Agriculture & Development"; 
// replace all the white space and the &
str.replace(/\s+/g, '').replace(/\&/,'_');

Upvotes: 1

Related Questions