代码之家  ›  专栏  ›  技术社区  ›  Mehdi Souregi

为什么替换“对我的案子不起作用?

c#
  •  0
  • Mehdi Souregi  · 技术社区  · 7 年前

    我是这样做的,就像这样 answer :

    string test = "test\"test";
    test = test.Replace("\\\"", "");
    

    但结果仍然是 test = "test\"test" .

    结果应该是 test = "testtest" ,为什么我的替代品不起作用?

    2 回复  |  直到 7 年前
        1
  •  7
  •   Selman Genç    7 年前

    因为你的绳子 test"test test\"test

    尝试使用逐字字符串:

    string test = @"test\""test"; // equivalent to test\\\"test