Replace single backslash with double backslash

前端 未结 5 2164
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 18:59

It seems simple enough, right? Well, I don\'t know.

Here\'s the code I\'m trying:

input = Regex.Replace(input, \"\\\\\", \"\\\\\\\\\\\\\");
         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-18 19:44

    If you want to replace one backslash with two, it might be clearer to eliminate one level of escaping in the regular expression by using @"..." as the format for your string literals, also known as a verbatim string. It is then easier to see that

    string output = Regex.Replace(input, @"\\", @"\\");
    

    is a replacement from \ to \\.

提交回复
热议问题