...

View Full Version : Check if String Contains



MISCHU
08-18-2011, 05:47 PM
Hi All

My code at the moment contains



Dim readout As String = stream.ReadToEnd
lbloverall.Text = readout


I want it to be like this however



Dim readout As String = stream.ReadToEnd

<<code to check if string contains "available">>
<<code to check if string contains "regthroughus">>
<<code to check if string contains "regthroughothers">>

<<IF String does contain "available THEN>>
lbloverall.Text = "available"

and so on
and so on.....


My question is how do I check the string (readout) and see if those words are in there to compile the if statements.

Thanks

Mike_O
08-18-2011, 08:52 PM
Hey MISCHU,

It's String.Contains(...). Here is a link: http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx#Y399.

p.s. This one you definitely could have Google'd

Mike

dotnetmind
08-21-2011, 12:51 PM
You could iterate trough the string's array and check your condition:



Foreach str as string in readout.Split("separator")
{

if(str.contains("available") || str.contains("available") || str.contains("available")
// Sequence
)

}

if Contains doesn't fit your need try equals.

Par1s
08-29-2011, 09:02 PM
Regex might be a good coding exercise if everything else fails. Use Contains for faster task completion though.

robertsams23
09-12-2011, 07:38 AM
try string.contains();

http://csharp.net-informations.com/string/csharp-string-contains.htm

rbt.

jassi.singh
09-27-2011, 08:13 PM
Hi,

Take input in array and iterate through each one by one and check for the string in current item of current iteration. Use contains() method.

ofesak
10-14-2011, 11:48 AM
Yes, just use string.Contains and then you can specify if to ignore case


___________________________________________________
http://makeflashgame.blogspot.com

jassi.singh
11-09-2011, 07:18 AM
Hi All

My code at the moment contains



Dim readout As String = stream.ReadToEnd
lbloverall.Text = readout


I want it to be like this however



Dim readout As String = stream.ReadToEnd

<<code to check if string contains "available">>
<<code to check if string contains "regthroughus">>
<<code to check if string contains "regthroughothers">>

<<IF String does contain "available THEN>>
lbloverall.Text = "available"

and so on
and so on.....


My question is how do I check the string (readout) and see if those words are in there to compile the if statements.

Thanks

Hello,

The method for this is
If (string.contiains("")
{
}
else
{
}

Thanks,



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum