user3720240
user3720240

Reputation:

Javascript replacing characters

I have set up a table in which you enter a search term and it opens a amazon link, however to get multiple keywords I need to add an +.

i have used var removeSymb = split(' ').join('+'); to replace it with a space however the link does not work and needs the +.

Update:

var url = "www.amazon"+country+"/gp/community-content-search/results/ref=cm_srch_q_rtr/?qu‌​ery="+keyword1+"&search-alias=community-reviews&Go.x=-646&Go.y=-262&idx.asin="+as‌​in+"&tag=amazon-review0a-21";

I have a form with asin, country and then a form to enter keywords this is the final string:

var finalAddress1 = "amazon"+country+"/gp/community-content-search/results/…;

For the search to have multiple keywords you need to add + between them but I need to remove this so you use space but the + is entered in the hyperlink

How do I do this?

Upvotes: 0

Views: 65

Answers (2)

PandAngular
PandAngular

Reputation: 101

You can use Regex for this.

var string = ' ';
var reg = new RegExp(string, 'g');

str = str.replace(reg, '');

Upvotes: 0

Joseph
Joseph

Reputation: 119847

Assuming str is the string containing your text:

var removeSymb = str.replace(/\s/g,'+');

Upvotes: 1

Related Questions