escaping quotes from strings using javascript?

后端 未结 3 1672
长发绾君心
长发绾君心 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 09:55

    use \ to escape the single quote like so:

    var name = 'Mc\'Obrian'
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-29 10:16

    var name = 'Mc\'Obrian'

    or

    var name = "Mc'Obrian"

    0 讨论(0)
提交回复
热议问题