Convert single-quoted string to double-quoted string

后端 未结 5 1859
无人及你
无人及你 2020-12-25 12:32

I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-25 13:20

    The difference is only on input. They are the same.

    s = "hi"
    t = 'hi'
    s == t
    

    True

    You can even do:

    "hi" == 'hi'
    

    True

    Providing both methods is useful because you can for example have your string contain either ' or " directly without escaping.

提交回复
热议问题