Replace single quote using javascript
This example will shows you how to replace single quote form a string. Default javascript replace method will replace the first occurrence of the single quote, to replace all the occurrences we have to use regular expression.
-
Removing all the single quotes from a string.
var outputstr= inputstring.replace(/'/g,'');
-
Replacing all the single quotes with double quote in a string.
var outputstr= inputstring.replace(/'/g,'"');
Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script language="javascript">
function RemoveSingleQuotes() {
var outputstr = $("#txtinput").val().replace(/'/g, '');
alert(outputstr);
}
function ReplaceSingleQuotes() {
var outputstr = $("#txtinput").val().replace(/'/g, '"');
alert(outputstr);
}
</script>
</head>
<body>
<div>
<input type="text" id="txtinput" />
<input type="button" value="Remove Single Quotes" onclick="RemoveSingleQuotes();" />
<input type="button" value="Replace Single Quotes" onclick="ReplaceSingleQuotes();" />
</div>
</body>
</html>
Useful Tools
Online Code Editor and Compiler
HTML Minifier
Online HTML Compiler/Preivew
Word Count Tool
Replace Text/Word tool
Latest Blogs
How to check if a canvas is empty or blank
Maintain div or panel scroll position after postback in asp.net update panel
Draggable button using jquery ui
Get total number of tables, views, stored procedures and functions count and names in sql server
JavaScript function to get date in mmddyyyy hhmmss ampm forma