alex
alex

Reputation: 235

.replace() function error

I am using the following function to replace ' in a string with

''

for ex

yourstring= "uncle Tom's cabin";
var crucial = yourstring.replace(/'/g, "''");

This does not work and I am not sure why!

Upvotes: 0

Views: 66

Answers (2)

Hogan
Hogan

Reputation: 70523

Try this:

  var yourstring = "uncle Tom's cabin";
  var crucial = yourstring.replace("'","''");

This will only replace one '

Upvotes: 0

medusa1414
medusa1414

Reputation: 1169

Your code works, you only misspelled "your string" variable.

yourstring= "uncle Tom's cabin";
var crucial = yourstring.replace(/'/g, "''");

Upvotes: 2

Related Questions