Process ASCII codes present in string

javascript

Solution

If @Bergi’s suggestion doesn’t help, try to trick the software by something like

str.replace(new RegExp("&"+"#"+"x27;", "g"), "'")

– basically splitting the numeric character reference into several pieces, so that the software that is messing with things can’t recognize it as such any more.

Problem

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 `'`.

Original source

Related problems