I have a commaseparated string of integers (from My.Settings).
I want to check if a specified number exists in the array.
My idea was to first convert to a string array and then do some kind of
search.
I can of course add them all manually to a hashtable, but is there some kind
of direct conversion that might help?

I don't have that many values so I prefer compact code before time
optimization.

Re: Elegant lookup? by Stephany

Stephany
Thu Jan 25 08:29:40 CST 2007

Dim FoundIt As Boolean = (myString.IndexOf(myInteger.ToString()) >= 0)


"Jakob Lithner" <jaklithn@noemail.noemail> wrote in message
news:2986A986-506C-4D97-8F9B-F23C33C3485D@microsoft.com...
>I have a commaseparated string of integers (from My.Settings).
> I want to check if a specified number exists in the array.
> My idea was to first convert to a string array and then do some kind of
> search.
> I can of course add them all manually to a hashtable, but is there some
> kind
> of direct conversion that might help?
>
> I don't have that many values so I prefer compact code before time
> optimization.



RE: Elegant lookup? by jaklithn

jaklithn
Thu Jan 25 08:31:01 CST 2007

I was just looking for methods on array and hashtable objects.
Generic List object had a convenient method that made it!

Dim ProfileArray() As String =
My.Settings.DefaultProfiles.Split(",;".ToCharArray)
Dim Profiles As New List(Of String)

Profiles.AddRange(ProfileArray)
.....
If Profiles.Contains(dr.ProfileID.ToString)) Then


Re: Elegant lookup? by jaklithn

jaklithn
Thu Jan 25 08:57:07 CST 2007

Will not work.
In this string "1,2,45,781,856" integer value 78 will be found but it should
not.

See my previous reply for a working solution.
Seems like you often refresh your brain just by telling someone else ... :-)

Thanks anyhow for your suggestion.