Remove Quotes from String

Remove quotes from a string, and replace with the html entity for the quote character.

This is useful if you want to save the text in a csv file or any other situation where allowing quotes would cause the string to terminate prematurely.

textcomment = removeQuotes(textcomment);

function removeQuotes(str) {
	return str.split('"').join('"');



textcomment = 'George said "Hi everyone" as he entered the room.';
textcomment = removeQuotes(textcomment);

Produces the result: 

textcomment == George said "Hi everyone" as he entered the room.

Which is displayed as quotes in a browser as shown below. This prevents additional quotes from terminating the string and causing javascript or html errors. The string below is displayed with " in place of quotes.

George said "Hi everyone" as he entered the room.

Copyright © Website Development | Disclaimer | Privacy Policy | Terms of Use