The solution 1 and 2 are very good and clearly give the answer for including
%
or
_
literal in the search expression.
In case you want to enter the
% _
in a normal way, for example from a
TextBox
from user input and then want to construct the filter expression, the following regular expression can be used to replace the occurances of
%
and
_
with
[%]
and
[_]
respectively.
string filterExpression = "a%b%_";
filterExpression = "%"+System.Text.RegularExpressions.Regex
.Replace(filterExpression,"([%_])","[$1]") + "%";
Console.WriteLine (filterExpression);