Escaping the escape character does not work – SQL LIKE Operator

后端 未结 2 1705
别那么骄傲
别那么骄傲 2020-12-21 04:56

I have used \\ as escape character for LIKE operator. I am escaping following four characters

1 % 2 [

2条回答
  •  粉色の甜心
    2020-12-21 05:34

    Modify your CustomFormat method like this:

    private static string CustomFormat(string input)
    {
        input = input.Replace(@"\", @"\\"); 
        input = input.Replace(@"%", @"\%");
        input = input.Replace(@"[", @"\[");
        input = input.Replace(@"]", @"\]");
        input = input.Replace(@"_", @"\_");
        return input;
    }
    

提交回复
热议问题