You can try to use a regular expression, and if it is a match you replace the match with an empty string.
Like this:
[UPDATE] Added 'or\s' to the expression, to get rid of double or's.
[UPDATE2] Updated the regex to match the actual requirement.
private static Regex expression = new Regex(@"or\s*distance=\s*'[a-z]+'", RegexOptions.IgnoreCase);
The expression basically means that you find the word
distance followed by
= and then
'any letter' within the quotes.
The match will occur in any place within the string.
\s* means zero or more white spaces
string s = @"where name='nilesh' or lastname='nilesh' or distance='nilesh' or gender='nilesh' where name = 'nilesh' or lastname = 'nilesh' or distance = '1' or gender = 'nilesh'";
string t = expression.Replace(s, "");
the result is
where name='nilesh' or lastname='nilesh' or gender='nilesh' where name = 'nilesh' or lastname = 'nilesh' or distance = '1' or gender = 'nilesh'
I don't know if you use quotes around numeric values or not, but it doesn't matter for the functionality.
When working with regular expressions it is good to have tool where you can test the expressions. I use this one,
RegExTest[
^], but there are other tools out there as well.
To learn about regular expressions you can use this site:
http://www.regular-expressions.info/[
^]