I need to replace any apostraphies (') in a string with \' using javascript, anyone know how i can do that?
Thanks
Love Sythe
xxx
| SitePoint Sponsor |
I need to replace any apostraphies (') in a string with \' using javascript, anyone know how i can do that?
Thanks
Love Sythe
xxx





Hi Sythe, you just need to use the replace method,
PaulCode:var st = "Paul's function"; var d = document; d.write(st+"<br>"); st = st.replace("'","\\ '"); d.write(st+"<br>");
PS (Remove the space between the two slashes and the apostrophe, vB don't show them correct)




If you want to explore this further, search for "javascript regular expressions" on your favourite search engine.
Bookmarks