1

Possible Duplicate:
JavaScript equivalent to printf/string.format
replace all occurrences in a string

see title. see the following variable, how can i replace all '%s' with other string?

var s = 'qwer%sqwer%s';

please advice

Community
  • 1
  • 1
Dorsey
  • 854
  • 3
  • 9
  • 17

4 Answers4

7

Use .replace method.

var s = 'qwer%sqwer%s';
s = s.replace(/%s/g, 'other');
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

Try this:

s.replace(/%s/g,'x')
codebox
  • 19,927
  • 9
  • 63
  • 81
0

You can Use replace() function for replacing string Ex.

 var getnewstring = s.replace("%s","YOUR STRING");
Sanket R. Patil
  • 311
  • 1
  • 2
  • 8
0

Use the .replace method

var s = 'qwer%sqwer%s';
s=s.replace('%s','your string')
document.write(s);
Amol Kolekar
  • 2,307
  • 5
  • 30
  • 45