build a list object from a comma-delimited list

G

giant food

I need some input from someone who is more familiar with the .NET
framework classes.

I have a few programming problems where the user passes in a
comma-delimited string of integers (e.g. "2,7,6,23,5"), and I need to
search it repeatedly as I'm looping over a recordset.

My usual method of doing this is to use the Split() function to parse
the string into an array, and then do sequential searches for
particular IDs like this:

for i as integer = lbound(arr) to ubound(arr)
if arr(i) = searchInt then
'int found; do something
end if
next

Is there a better way? I've also tried [Array].BinarySearch, for when
my list is longer. I'd like to use some sort of list object that I
build given the comma-separated list, which I could verify was only a
list of integers (or some other type). Thanks

--Frank
 
C

Cor

Hi Frank,

A pity, that you did not use the dataset.

With a dataset, datatable, dataview you could have done someting as

for i as integer = 0 to arr.length-1
dv.rowfilter = "myfield = " & arr(i)
for y as integer = 0 to dv.count
'do something with every field in the selected rows
next
next

But with the recordset I do not know how to make it more efficient.

Cor
 

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

Top