Ok. This may be a dumb question but I am stuck.
In my javascript, I have a string variable that contains '
which stands for single quote. e.g. some_text_'_some_text
Now, I want to replace this with the actual single quote like some_text_'_some_text
.
Obvious way would be using str.replace(/'/g,"'")
but the problem is I write this javascript code into a third party software that replaces '
by '
when I save the script. So, if I open script again, it shows str.replace(/'/g,"'")
. So when the script runs, it does not do replace operation correctly.
One would ask why do I need this replace to work?
The reason is that this variable is passed on to build a SQL query and I don't want '
in my query. I want it to be '
instead which I can escape in SQL.
EDIT
So, I realized the reason for this behavior and potential answerers may want to take this into account. The software I work with stores all its files as XML including javascript code I write. So, it converts all special characters to HTML codes while saving and parses them back when it reads it. That's the reason '
gets converted to '
.