Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  136] [ 4]  / answers: 1 / hits: 27182  / 15 Years ago, sun, january 10, 2010, 12:00:00

How can I remove the semicolon (;) from a string by using JavaScript?



For example:



var str = '<div id=confirmMsg style=margin-top: -5px;>'


How can I remove the semicolon from str?


More From » javascript

 Answers
83

You can use the replace method of the string object. Here is what W3Schools says about it: JavaScript replace().



In your case you could do something like the following:



str = str.replace(;, );


You can also use a regular expression:



str = str.replace(/;/g, );


This will replace all semicolons globally. If you wish to replace just the first instance you would remove the g from the first parameter.


[#97871] Thursday, January 7, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;