Prasad
Prasad

Reputation: 59491

Replace two double quotes with single one using jquery

How do I replace two double quotes into single one using jQuery?

For example: I need to replace

Sam is at his ""Home""

to

Sam is at his "Home"

Looking for something similar to this regex (which replaces double quotes to single quotes):

mystring.replace(/"/g, "'")

Upvotes: 4

Views: 15185

Answers (1)

Kobi
Kobi

Reputation: 137997

try this:

mystring = mystring.replace(/""/g, '"');

The regex captures two double quotes and replaces them with one. We're using a regex to replace more than a single match (JavaScript's replace will only replace the first one).

Note that the second argument to replace is a string. To represent " in a string we need to escape it: "\"", or use a single quote string: '"'. JavaScript supports both.

Upvotes: 8

Related Questions