473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking a string for two constraints

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,

Dec 3 '07 #1
7 1819
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!
|
*************************************************
"Brian Cook" <br********@bnsf.comwrote in message
news:AA**********************************@microsof t.com...
>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,

Dec 3 '07 #2
Yes, I have considered using Regular expressions, however I just am not
grasping the use of them.

"Brian Cook" wrote:
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,
Dec 3 '07 #3
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" wrote:
Yes, I have considered using Regular expressions, however I just am not
grasping the use of them.

"Brian Cook" wrote:
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,
Dec 3 '07 #4
Cowboy (Gregory A. Beamer) <No************@comcast.netNoSpamMwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 3 '07 #5
On Dec 3, 5:05 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Cowboy (Gregory A. Beamer) <NoSpamMgbwo...@comcast.netNoSpamMwrote:
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.

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk
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 ;)
Dec 3 '07 #6
Jon that worked. Now I see where my mistake was.

I added a second close paren after the first constraint.

Thanks I appreciate it.

"Jon Skeet [C# MVP]" wrote:
Cowboy (Gregory A. Beamer) <No************@comcast.netNoSpamMwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 3 '07 #7
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!

"Arnshea" wrote:
On Dec 3, 5:05 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Cowboy (Gregory A. Beamer) <NoSpamMgbwo...@comcast.netNoSpamMwrote:
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.

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk

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 ;)
Dec 3 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8096
by: Dan Hartshorn | last post by:
Anybody know if there is a system function that can be used from a stored procedure that determines if a given primary key has existing dependencies? I want to make a check for this and if there...
1
1903
by: halcyon943 | last post by:
have 4 folders that I watch and need to move files from to another location. Three constraints: -Finish time. Make sure the program stops transferring files at a specific time -Number of...
4
12714
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
2
3370
by: dbonin1599 | last post by:
I have the following code, the first set of code is the SQL version, the second set of code is an attempt to put the code into a VB String see "UpdateVariations". I need help, I think most of it is...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.