
Compare & Filter Strings/Arrays
On a page I'm working on, I have 4 dynamicallycreated strings I'd like to compare...each string is just a commaseparated list of up to 20 different numbers. What I want to do is to find all numbers that appear in more than one string, and then make a new array with just those numbers, sorting by numbers which appeared the greatest number of times first. I'm way too retarded to figure this out, can anyone help? mhat@samplehead.com

RE: Compare & Filter Strings/Arrays
There are so many ways to do this that I almost hesitate to suggest any one way lest you decide it is the only one!<BR><BR>Do you have any foreknowledge about the *range* of numbers that will be found in the lists? That is, do you know that they will only be integers from 1 to 1000 or something like that? If your answer to that is "yes," then one way would be to simply create an array as big as the expected range and then "count" things by bumping the cell that corresponds to the number(s):<BR><BR><%<BR>Dim counts(1000)<BR><BR>Sub processString( str )<BR> dim temp, i, n<BR> temp = Split(str,",")<BR> For i = 0 To UBound( temp )<BR> n = CInt( temp( i ) )<BR> counts( n ) = counts( n ) + 1<BR> Next<BR>End Sub<BR>%><BR><BR>Then, after processing all the strings through that SUB, you simply look through the "counts" array for all elements that have a count greater than 1 as well as looking for the greatest of those.<BR><BR>**************<BR><BR>But let's assume that you have no idea what the range of numbers will be, and maybe you have numbers such as 0.33333333333 and 3.14159265.<BR><BR>Then the best way is probably to convert each string to an array and do a "merge/sort". This is hairy enough that I won't go into it unless you need it.<BR><BR>

RE: Compare & Filter Strings/Arrays
I don't see how this works exactly... <BR>If I had 4 strings:<BR>"1, 2, 3, 4"<BR>"1, 4, 6, 7"<BR>"1, 2, 9, 11"<BR>"2, 4, 9, 11"<BR>I'd want the results to list:<BR>"1, 2, 4, 9, 11, 3, 6, 7", i.e. list the numbers that occurred the most times out of all 4 strings first.<BR>Would the code you wrote do this? I don't see how really... Please help if you can, I do appreciate it, and if you could provide a means of contacting you directly, that would be most appreciated.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

