Hi all,
having a string like this:
(CustomerDescH LIKE '%test2%')
how can I create a new string like this one:
(CustomerDescH LIKE '%test2%' OR CustomerNumber LIKE '%test2%')
Thanks a lot.
--
Luigi
PS
I'm using C# 2.0
Seems like your description is being misunderstood a bit. I'm assuming you are writing
some kind of query filter that modifies existing queries (as String) to add a second
condition.
I'm not sure how much of the original query syntax is fixed, but using this somewhat
unwieldy but very powerful method, you can easily decide on that whenever you like.
If you're not familiar with regular expressions, this is an excellent way to start!
First, add "using System.Text.RegularExpressions;", and then do something like this
(sin, the input string, gets modified but only if the regex matches):
// Match any string that has a single-quoted string in it, and produce three parts,
// "pre", "str" and "post"
Regex strmatchex = new Regex("^(?<pre>[^']*')(?<str>[^']*)(?<post>'.*)$");
// ...or a much stricter version
// Regex strmatchex = new Regex("^(?<pre>\\(CustomerDescH LIKE ')(?<str>[^']*)(?<post>'\\))$");
// Apply the regular expression to the input string
Match m = strmatchex.Match(sin);
// If the string matches, add some more text, including an extra copy of the "str" part
if (m.Success) {
sin = m.Groups["pre"].Value + m.Groups["str"].Value +
"' OR CustomerNumber LIKE '" +
m.Groups["str"].Value + m.Groups["post"].Value;
}
/Hans