escaping quotes from strings using javascript?

后端 未结 3 1710
长发绾君心
长发绾君心 2021-01-29 09:50

For instance say I have the string:

var name = \'Mc\'Obrian\'

I want to be able to escape the the first quote and the last quote only, not the

3条回答
  •  被撕碎了的回忆
    2021-01-29 10:04

    The following will properly escape the single quote given your current code:

    var name = 'Mc\'Obrian'
    

    I would encourage you to read the following tutorial about strings. If you are interested in performance considerations, read this question.

提交回复
热议问题