How to replace straight quotation mark (")

后端 未结 3 1482
我寻月下人不归
我寻月下人不归 2021-01-04 08:32

I would like to replace a straight quotation mark (\") using C#.

I might be missing something small, but I can\'t get it with a normal string.Replace();

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 09:13

    someWord.Replace("\"", "&");
    

    or

    someWord.Replace(@"""", "&");
    

    (Quotes are escaped as \" in regular strings and "" in verbatim strings.)

    But you probably meant

    someWord.Replace("\"", """);
    

    since the HTML entity for straight quotation marks is ", not &.

提交回复
热议问题