Escape Quotes / Add Slashes

Hi,

Is there a servoy function to escape quotes?

Something like addSlashes("Don't Know") returns "Don\'t Know"

Thanks,
Andrew

There isn't, but something like:

var text = arguments[0];

var length = text.length;
var pos = 0;

while (pos < length) {
    if (text.charAt(pos) == "'" || text.charAt(pos) == '"') {
        text = (text.substr(0, pos) + utils.getUnicodeCharacter(92) + text.substr(pos, length-pos));
        length++;
        pos++;
    }
    pos++;
}

return text;

should do the trick.

Out of my head, but I think this does the same:

var text = arguments[0]; 
var text = utils.stringReplace(text,"'","\'")
return text

Not really, because the \' is just considered to be '.

In other words:

utils.stringReplace(text,"'","\'")
and

utils.stringReplace(text,"'","'")

are considered the same.

but on the other hand, \ is considered to be \, so

var text = arguments[0];
var text = utils.stringReplace(text,"'","\\'")
return text

should also work :)

ah oke, now I see.