Regex for replacing a single-quote with two single-quotes

前端 未结 8 1502
迷失自我
迷失自我 2020-12-16 09:24

I\'m running into an issue that I think is being caused by needing to double-up on some single quotes inside a string. However, JS\'s string.replace uses RegEx, and I\'ve ne

8条回答
  •  忘掉有多难
    2020-12-16 09:39

    Try this:

    function QuoteEncoding(strvalue) {
        var strquotes = /(')/g;
        return "'" + strvalue.replace(strquotes, "''") + "'";
    }
    

    call this method as follows:

    QuoteEncoding(strvalue);
    

提交回复
热议问题