I need to use a BindingSource Filter property to search for names in a string field. That is easy enough, unless the name contains a single quote (apostrophe) such as "O'BRIEN" or similar names. VS Help says special characters should be escaped by enclosing them in square brackets. This works for some characters such as %, \ and even the bracket characters themselves, but it fails with a syntax error if I attempt to escape a single quote. I also tried to escape using \ but that doesn't work either.

Does anyone know of a way to use expressions to search for strings containing single quotes?

Hi,

simply replace one apostrophe by two apostrophes like:

string sFilter = "something apostophe'd";
string myFilter = sFilter.Replace("'","''");

Hope that helps

Well, I was sure I'd tried that, but I was wrong - that works. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.