473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Contains for string?

Tom
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If

Nov 21 '05 #1
17 8068
Is String.IndexOfAny() what you are looking for?

"Tom" <to*@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If


Nov 21 '05 #2
Tom,
As Shiva suggests, you can use String.IndexOfAny, something like:
If strTest.IndexOfAny("ABC".ToCharArray) <> -1 Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If
Or

If strTest.IndexOfAny(New Char() {"A"c, "B"c, "C"c}) <> -1 Then

NOTE: "A"c is a char literal, while "A" is a string literal.

Depending on how often I was using the above, I would consider making the
char array Static to the routine.

Static anyOf() As Char = New Char() {"A"c, "B"c, "C"c}
If strTest.IndexOfAny(anyOf) <> -1 Then

Hope this helps
Jay

"Tom" <to*@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl... Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If

Nov 21 '05 #3
Tom
Shiva: Yes, that works for CHARACTERs, but not for strings. I probably
should have made my example
as such:

strTest = "The cat jumped over the sleepy dog."
If strTest Contains ("cat","dog", "sleep") Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

I -could- write my own function easily enough for this, but it seems like
the framework should have a similar string function somewhere.

Tom

"Shiva" <sh******@online.excite.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Is String.IndexOfAny() what you are looking for?

"Tom" <to*@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If

Nov 21 '05 #4
Tom,

You cannot, you should or use a Regex or use a loop with the normal indexof

Where the performance decission when to use the regex is in my opinion about
20 words to search for.

Cor
Nov 21 '05 #5
Tom,
I think you are going to have to create your own routine...

I would consider using a RegEx in that routine.

Const pattern As String = "cat|dog|sleep"
Static theRegEx As New System.Text.RegularExpressions.Regex(pattern,
Text.RegularExpressions.RegexOptions.Compiled)
If theRegEx.IsMatch(strTest) Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

Of course if "cat","dog", "sleep" are dynamic, you could build the pattern
with String.Join:

Dim pattern As String = String.Join("|", New String() {"cat", "dog",
"sleep"})
If System.Text.RegularExpressions.Regex.IsMatch(patte rn, strTest)
Then

Which I used would depending on the whether or not the strings I was looking
for were static or dynamic & how often the routine was being called...

Hope this helps
Jay

"Tom" <to*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Shiva: Yes, that works for CHARACTERs, but not for strings. I probably
should have made my example
as such:

strTest = "The cat jumped over the sleepy dog."
If strTest Contains ("cat","dog", "sleep") Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

I -could- write my own function easily enough for this, but it seems like
the framework should have a similar string function somewhere.

Tom

"Shiva" <sh******@online.excite.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Is String.IndexOfAny() what you are looking for?

"Tom" <to*@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If


Nov 21 '05 #6
Doh!,
Dim pattern As String = String.Join("|", New String() {"cat",
"dog", "sleep"})
If System.Text.RegularExpressions.Regex.IsMatch(patte rn, strTest)
Reversed the patterns, it should be:

If Regex.IsMatch(strTest, pattern) Then

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl... Tom,
I think you are going to have to create your own routine...

I would consider using a RegEx in that routine.

Const pattern As String = "cat|dog|sleep"
Static theRegEx As New
System.Text.RegularExpressions.Regex(pattern,
Text.RegularExpressions.RegexOptions.Compiled)
If theRegEx.IsMatch(strTest) Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

Of course if "cat","dog", "sleep" are dynamic, you could build the pattern
with String.Join:

Dim pattern As String = String.Join("|", New String() {"cat",
"dog", "sleep"})
If System.Text.RegularExpressions.Regex.IsMatch(patte rn, strTest)
Then

Which I used would depending on the whether or not the strings I was
looking for were static or dynamic & how often the routine was being
called...

Hope this helps
Jay

"Tom" <to*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Shiva: Yes, that works for CHARACTERs, but not for strings. I probably
should have made my example
as such:

strTest = "The cat jumped over the sleepy dog."
If strTest Contains ("cat","dog", "sleep") Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

I -could- write my own function easily enough for this, but it seems like
the framework should have a similar string function somewhere.

Tom

"Shiva" <sh******@online.excite.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Is String.IndexOfAny() what you are looking for?

"Tom" <to*@nospam.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If



Nov 21 '05 #7
"Tom" <to*@nospam.com> schrieb:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If


For reasons of readability, I prefer this solution:

\\\
Dim s As String = _
"Quidquid id est timeo Danaos et dona ferentes."
If _
InStr(s, "Quidquid") AndAlso _
InStr(s, "timeo") AndAlso _
InStr(s, "dona") _
Then
MsgBox("True")
Else
MsgBox("False")
End If
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #8
Herfried,
You raised an interesting question. Does Tom want to know if strTest
contains all three or one of?

Its harder with RegEx to check to see if it contains all three...

Wondering
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
"Tom" <to*@nospam.com> schrieb:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If


For reasons of readability, I prefer this solution:

\\\
Dim s As String = _
"Quidquid id est timeo Danaos et dona ferentes."
If _
InStr(s, "Quidquid") AndAlso _
InStr(s, "timeo") AndAlso _
InStr(s, "dona") _
Then
MsgBox("True")
Else
MsgBox("False")
End If
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #9
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
You raised an interesting question. Does Tom want to know
if strTest contains all three or one of?
First I tested if 'String' contains a 'Contains' method, but it doesn't
contain such a method.

BTW: My solution can be simply adapted by replacing 'AndAlso' with 'OrElse'
in order to check for the occurance of one (or more) of the substrings in
the string.
Its harder with RegEx to check to see if it contains all
three...


Especially for longer strings, the way I propagate may be inefficient, but I
don't know how Regex is implemented...

Wondering too...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #10
Herfried,
Its harder with RegEx to check to see if it contains all
three...
Especially for longer strings, the way I propagate may be inefficient, but
I don't know how Regex is implemented...


Longer input or longer list of words?

RegEx has no syntax that states "this & that" per se (you would need to
create a convoluted pattern), it only has "this or that" (via "this|that")
so checking for one of significant number of words with a regex is
relatively easy (see my other post). Checking for all of a list of words
with RegEx would be significantly hard!

As I've stated before, I would not worry about performance until the routine
was proven to be a performance problem. I would go with one of the two RegEx
I gave earlier based on if the list of words was static or dynamic... If the
RegEx proved to have a performance problem then I would replace the
Algorithm with a more efficient one... (if one could be found that was truly
more efficient in the context of the routine).

Hope this helps
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl... Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
You raised an interesting question. Does Tom want to know
if strTest contains all three or one of?


First I tested if 'String' contains a 'Contains' method, but it doesn't
contain such a method.

BTW: My solution can be simply adapted by replacing 'AndAlso' with
'OrElse' in order to check for the occurance of one (or more) of the
substrings in the string.
Its harder with RegEx to check to see if it contains all
three...


Especially for longer strings, the way I propagate may be inefficient, but
I don't know how Regex is implemented...

Wondering too...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #11
Tom
No, actually all I would want to know is if any of the strings exists in the
line. I want it to work pretty much the way the SQL IN verb works. i.e.
where Status in ('ACTIVE','OTHER')

Which brings up an interesting question: Is there any kind of IN verb
anywhere in VB.NET or the .NET framework?

But thanks for all the suggestions; I think I will try to make up a function
or something that I can call to do this.

Tom

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP11.phx.gbl...
Herfried,
You raised an interesting question. Does Tom want to know if strTest
contains all three or one of?

Its harder with RegEx to check to see if it contains all three...

Wondering
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
"Tom" <to*@nospam.com> schrieb:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For instance, I want to do something like the following:

If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If


For reasons of readability, I prefer this solution:

\\\
Dim s As String = _
"Quidquid id est timeo Danaos et dona ferentes."
If _
InStr(s, "Quidquid") AndAlso _
InStr(s, "timeo") AndAlso _
InStr(s, "dona") _
Then
MsgBox("True")
Else
MsgBox("False")
End If
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 21 '05 #12
Tom
Herfried: Yep, I can do it this way, and that is pretty much how I have been
doing it. I just thought there had to be some other intrinsic built-in way
of doing it without having to write the code. That would be a good function
to have in the .NET framework.

I wonder if using a RegEx or using your method would be faster?

Tom

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl...
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
You raised an interesting question. Does Tom want to know
if strTest contains all three or one of?
First I tested if 'String' contains a 'Contains' method, but it doesn't
contain such a method.

BTW: My solution can be simply adapted by replacing 'AndAlso' with

'OrElse' in order to check for the occurance of one (or more) of the substrings in
the string.
Its harder with RegEx to check to see if it contains all
three...
Especially for longer strings, the way I propagate may be inefficient, but

I don't know how Regex is implemented...

Wondering too...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #13
Tom,

That is very easy that MVB "Instr" method is the fastest for finding
"strings", it outclasses all other methods.

We have made some testing in past about this in this newsgroup, here is the
thread

http://tinyurl.com/3z2nk

Cor

"Tom" <to*@nospam.com>
Herfried: Yep, I can do it this way, and that is pretty much how I have
been
doing it. I just thought there had to be some other intrinsic built-in way
of doing it without having to write the code. That would be a good
function
to have in the .NET framework.

I wonder if using a RegEx or using your method would be faster?

Tom

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eO**************@TK2MSFTNGP10.phx.gbl...
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
> You raised an interesting question. Does Tom want to know
> if strTest contains all three or one of?


First I tested if 'String' contains a 'Contains' method, but it doesn't
contain such a method.

BTW: My solution can be simply adapted by replacing 'AndAlso' with

'OrElse'
in order to check for the occurance of one (or more) of the substrings in
the string.
> Its harder with RegEx to check to see if it contains all
> three...


Especially for longer strings, the way I propagate may be inefficient,
but

I
don't know how Regex is implemented...

Wondering too...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 21 '05 #14
"Cor Ligthert" <no************@planet.nl> schrieb:
That is very easy that MVB "Instr" method is the fastest for finding
"strings", it outclasses all other methods.

We have made some testing in past about this in this newsgroup, here
is the thread

http://tinyurl.com/3z2nk


I think the theoretically fastest implementation would be an adapted version
of the Boyer Moore algorithm or the KMP pattern matching algorithm. By
calling 'InStr' three times (for looking for the occurance of three strings
in the text) there may be comparisons done that don't need to be done with a
specialized implementation.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #15
Herfried,

I was thinking about just making a sample method as is the indexofArray and
than with strings, cannot be that hard when you everytime move the index of
a string one position and test it than against the string when the position
is less than the lenght of the search word.

Than would the instr be faster than the indexof, however it would be a
little bit strange routine when I would make this, because I would use the
substring instead of the Mid.

Both should be very easy to be done and probably be the fastest routine, and
when you are sure it are bytes and no unicodes even faster to be done with a
bytearray.

However with methods in previouw message I did mean all methods which are
standard in dotnet as regex, indexof, etc.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at>

"strings", it outclasses all other methods.

We have made some testing in past about this in this newsgroup, here
is the thread

http://tinyurl.com/3z2nk


I think the theoretically fastest implementation would be an adapted
version of the Boyer Moore algorithm or the KMP pattern matching
algorithm. By calling 'InStr' three times (for looking for the occurance
of three strings in the text) there may be comparisons done that don't
need to be done with a specialized implementation.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #16
Tom,
As we all suggested there is no builtin "In" function per se.

I would use the RegEx as its IMHO the "simplest" & "cleanest"
implementation! However! you need to understand RegEx to be comfortable
using it, luckily this regex is easy. Also you may need to get over the
perception that RegEx is slow. Yes it has some inherit overhead the other
methods do not, however that overhead may be warranted for the simplicity of
the routine. Also based on the context the overhead of the RegEx may be
lower, significantly lower, then other routines.

Note: I would only use the RegEx method for checking Strings, if I was
creating an "In" for other types I would pick an algorithm that was more
friendly for that type.

Here's one possibility for an "In" function based on RegEx.

Public Shared Function [In](ByVal input As String, ByVal ParamArray
words() As String) As Boolean
Dim pattern As String = String.Join("|", words)
Return System.Text.RegularExpressions.Regex.IsMatch(input , pattern)
End Function

Then to use it you simple need to:

strTest = "The cat jumped over the sleepy dog."
If [In](strTest, "cat","dog", "sleep") Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

If the above RegEx version proved to be a performance problem I would then
consider using a For Each loop.

Public Shared Function [In](ByVal input As String, ByVal ParamArray
words() As String) As Boolean
For Each word As String In words
If input.IndexOf(word) <> -1 Then
Return True
End If
Next
Return False
End Function

I would consider creating an object that contained a list of words, which
had a method the checked to see if a string had one of those words.

Public Class ValidValues

Private ReadOnly m_regex As System.Text.RegularExpressions.Regex

Public Sub New(ByVal ParamArray words() As String)
Dim pattern As String = String.Join("|", words)
m_regex = New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compil ed)
End Sub

Public Function IsMatch(ByVal value As String) As Boolean
Return m_regex.IsMatch(value)
End Function

End Class
Dim values As New ValidValues("cat", "dog", "sleep")
If values.IsMatch(strTest) Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If
Return

Dim statusValues As New ValidValues("ACTIVE","OTHER")
If statusValues.IsMatch(Status) Then
...

Notice in both cases that the actual method (algorithm) of matching is
hidden (encapsulated) within either the object or the function itself. Which
allows you to replace the Algorithm with a more efficient one if needed...

Whether I used the Function or Class would depend on how the function or
class was being within my program... Using Refactoring
http://www.refactoring.com I can change between the two...

As the others pointed out there are other equally valid ways to implement
the above. There are also methods that have yet to be mentioned, such as
using a HashTable or using a DataSet, plus still others. Which one you
should use REALLY depends on the context of what you are doing!

For example if your status value is in a DataTable, you can use a filter
statement that include an "In" statement, on either DataTable.Select or
DataView.RowFilter. Like wise of the list of valid statues are in a
DataTable, you could use DataTable.Rows.Find assuming that the status was
the primary key to that table, or use filter & either DataTable.Select or
DataView.RowFilter...

Hope this helps
Jay


"Tom" <to*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
No, actually all I would want to know is if any of the strings exists in
the
line. I want it to work pretty much the way the SQL IN verb works. i.e.
where Status in ('ACTIVE','OTHER')

Which brings up an interesting question: Is there any kind of IN verb
anywhere in VB.NET or the .NET framework?

But thanks for all the suggestions; I think I will try to make up a
function
or something that I can call to do this.

Tom

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP11.phx.gbl...
Herfried,
You raised an interesting question. Does Tom want to know if strTest
contains all three or one of?

Its harder with RegEx to check to see if it contains all three...

Wondering
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
> "Tom" <to*@nospam.com> schrieb:
>> Is there such a thing as a CONTAINS for a string variable in VB.NET? For >> instance, I want to do something like the following:
>>
>> If strTest Contains ("A","B", "C") Then
>> Debug.WriteLine("Found characters")
>> Else
>> Debug.WriteLine("Did NOT find characters!")
>> End If
>>
>
> For reasons of readability, I prefer this solution:
>
> \\\
> Dim s As String = _
> "Quidquid id est timeo Danaos et dona ferentes."
> If _
> InStr(s, "Quidquid") AndAlso _
> InStr(s, "timeo") AndAlso _
> InStr(s, "dona") _
> Then
> MsgBox("True")
> Else
> MsgBox("False")
> End If
> ///
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



Nov 21 '05 #17
Tom
Thanks, Jay, this helped greatly.

Tom

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u6**************@TK2MSFTNGP14.phx.gbl...
Tom,
As we all suggested there is no builtin "In" function per se.

I would use the RegEx as its IMHO the "simplest" & "cleanest"
implementation! However! you need to understand RegEx to be comfortable
using it, luckily this regex is easy. Also you may need to get over the
perception that RegEx is slow. Yes it has some inherit overhead the other
methods do not, however that overhead may be warranted for the simplicity of the routine. Also based on the context the overhead of the RegEx may be
lower, significantly lower, then other routines.

Note: I would only use the RegEx method for checking Strings, if I was
creating an "In" for other types I would pick an algorithm that was more
friendly for that type.

Here's one possibility for an "In" function based on RegEx.

Public Shared Function [In](ByVal input As String, ByVal ParamArray
words() As String) As Boolean
Dim pattern As String = String.Join("|", words)
Return System.Text.RegularExpressions.Regex.IsMatch(input , pattern) End Function

Then to use it you simple need to:

strTest = "The cat jumped over the sleepy dog."
If [In](strTest, "cat","dog", "sleep") Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If

If the above RegEx version proved to be a performance problem I would then
consider using a For Each loop.

Public Shared Function [In](ByVal input As String, ByVal ParamArray
words() As String) As Boolean
For Each word As String In words
If input.IndexOf(word) <> -1 Then
Return True
End If
Next
Return False
End Function

I would consider creating an object that contained a list of words, which
had a method the checked to see if a string had one of those words.

Public Class ValidValues

Private ReadOnly m_regex As System.Text.RegularExpressions.Regex

Public Sub New(ByVal ParamArray words() As String)
Dim pattern As String = String.Join("|", words)
m_regex = New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compil ed)
End Sub

Public Function IsMatch(ByVal value As String) As Boolean
Return m_regex.IsMatch(value)
End Function

End Class
Dim values As New ValidValues("cat", "dog", "sleep")
If values.IsMatch(strTest) Then
Debug.WriteLine("Found strings")
Else
Debug.WriteLine("Did NOT find strings!")
End If
Return

Dim statusValues As New ValidValues("ACTIVE","OTHER")
If statusValues.IsMatch(Status) Then
...

Notice in both cases that the actual method (algorithm) of matching is
hidden (encapsulated) within either the object or the function itself. Which allows you to replace the Algorithm with a more efficient one if needed...

Whether I used the Function or Class would depend on how the function or
class was being within my program... Using Refactoring
http://www.refactoring.com I can change between the two...

As the others pointed out there are other equally valid ways to implement
the above. There are also methods that have yet to be mentioned, such as
using a HashTable or using a DataSet, plus still others. Which one you
should use REALLY depends on the context of what you are doing!

For example if your status value is in a DataTable, you can use a filter
statement that include an "In" statement, on either DataTable.Select or
DataView.RowFilter. Like wise of the list of valid statues are in a
DataTable, you could use DataTable.Rows.Find assuming that the status was
the primary key to that table, or use filter & either DataTable.Select or
DataView.RowFilter...

Hope this helps
Jay


"Tom" <to*@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
No, actually all I would want to know is if any of the strings exists in
the
line. I want it to work pretty much the way the SQL IN verb works. i.e.
where Status in ('ACTIVE','OTHER')

Which brings up an interesting question: Is there any kind of IN verb
anywhere in VB.NET or the .NET framework?

But thanks for all the suggestions; I think I will try to make up a
function
or something that I can call to do this.

Tom

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:uQ*************@TK2MSFTNGP11.phx.gbl...
Herfried,
You raised an interesting question. Does Tom want to know if strTest
contains all three or one of?

Its harder with RegEx to check to see if it contains all three...

Wondering
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
> "Tom" <to*@nospam.com> schrieb:
>> Is there such a thing as a CONTAINS for a string variable in VB.NET?

For
>> instance, I want to do something like the following:
>>
>> If strTest Contains ("A","B", "C") Then
>> Debug.WriteLine("Found characters")
>> Else
>> Debug.WriteLine("Did NOT find characters!")
>> End If
>>
>
> For reasons of readability, I prefer this solution:
>
> \\\
> Dim s As String = _
> "Quidquid id est timeo Danaos et dona ferentes."
> If _
> InStr(s, "Quidquid") AndAlso _
> InStr(s, "timeo") AndAlso _
> InStr(s, "dona") _
> Then
> MsgBox("True")
> Else
> MsgBox("False")
> End If
> ///
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



Nov 21 '05 #18

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

Similar topics

2
by: Aleksi Kallio | last post by:
I want to say something like this: <xsl:if test="contains($my-string, {'banana', 'apple', 'lemon'})"> Ie. I want to do "contains" against many strings. I don't want to write them all manually...
2
by: Piotr Szukalski | last post by:
Hi! I have trouble with 'Contains' method in ListViewItemCollection class - it seems like it nevers calls 'Equals' method of class inherited from ListViewItem... I've found that ListViewItem...
2
by: Dot net work | last post by:
Hello, My simple code is here: Public Class MyDictionary Inherits System.Collections.DictionaryBase Private Class MyElement Public Overloads Overrides Function Equals(ByVal obj As Object)...
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
14
by: Ralf Rottmann \(www.24100.net\) | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
4
by: Jeff | last post by:
Hey ..NET 3.5 I'm trying to search a string to determine if the string contains </table>, but string.Contains don't find it. I've used WebRequest/WebReponse to retrieve the html from a...
8
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
1
by: Jon Skeet [C# MVP] | last post by:
On Apr 30, 3:56 pm, Raja <rajesh.mad...@gmail.comwrote: Well, in fact it's *not* working fine - it's not behaving the same on SQL server as it would be in normal code. String.Contains is case-...
8
by: SMJT | last post by:
Does anyone know why the string contains function always returns true if the token is an empty string? I expected it to return false. "AnyOldText".Contains("") or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.