-1

i Have a string in that sometimes ? sometimes � will come i want to replace it with single quotation.

i want some thing like this:

var Option = Option.replace("?"|"�", "'"); 

But this code is not working how can i write string replace in javascript.?

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Mr world wide
  • 4,696
  • 7
  • 43
  • 97

1 Answers1

2

You use a regular expression with a character class:

option = option.replace(/[?�]/g, "'");

var option = "Testing? Testing� Testing";
option = option.replace(/[?�]/g, "'");
console.log(option);

I added the g flag on the theory you probably don't want to replace just the first one. If you do want to replace just the first one, remove the g flag.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875