-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.?

2
  • 1
    If your question is how to do this in JavaScript, don't spam the PHP tags php and str-replace. Commented Apr 12, 2017 at 8:33
  • Use the global regex flag? Commented Apr 12, 2017 at 8:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

There has to be a dupetarget for this. Edit: Yup.
This one or ...
It worked thankx for your time.. Actually it is a utf 8 issue im not able to fix that so im doing in this way. is it a correct way..?
@evolutionxbox: That one's much more complicated, but I found one. :-)
@AbdulWaheed: It's conceptually identical, just look up how to use preg_replace.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.