Checking a string for two constraints

  • Thread starter Thread starter Brian Cook
  • Start date Start date
B

Brian Cook

I need to check to see if a string contains two different constraints. I
currently use this else if statement to look for the first constraints;

else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG"))
{
i += 112;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont,
rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}

I need to check for this constraint and need to check to see if the string
contains "RX" in it also.

Thanks,
 
Have you considered using Regular Expressions? It allows for an or condition
and is likely to be faster than the Contains type of searching. It certainly
is easier to search for multiple conditions.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
Yes, I have considered using Regular expressions, however I just am not
grasping the use of them.
 
if you do not want to get into REGEX (I agree that you should) then you would
need to use logic like this:


else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG") &&
lines[lineNum].Contains("RX" )

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



Brian Cook said:
Yes, I have considered using Regular expressions, however I just am not
grasping the use of them.

Brian Cook said:
I need to check to see if a string contains two different constraints. I
currently use this else if statement to look for the first constraints;

else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG"))
{
i += 112;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont,
rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}

I need to check for this constraint and need to check to see if the string
contains "RX" in it also.

Thanks,
 
Cowboy (Gregory A. Beamer) said:
Have you considered using Regular Expressions? It allows for an or condition
and is likely to be faster than the Contains type of searching. It certainly
is easier to search for multiple conditions.

I don't know - I'd far rather write:

if (line.Contains("first string") &&
line.Contains("second string"))

than read the regular expression version of it - especially if there
are bits which need escaping etc.
 
I don't know - I'd far rather write:

if (line.Contains("first string") &&
line.Contains("second string"))

than read the regular expression version of it - especially if there
are bits which need escaping etc.

I Have to agree here. For a small number of exact match substrings a
Regex would work but I'd probably just use IndexOf or Contains...

On the other hand, Regexes are so useful it might be a good excuse to
start learning about them ;)
 
Jon that worked. Now I see where my mistake was.

I added a second close paren after the first constraint.

Thanks I appreciate it.
 
I plan to learn them now. I have as yet needed them, however I do see a time
when I will need them.

Thanks all of you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top