tags:

views:

59

answers:

2

Hello,

I have two comma separated lists:-

36,189,47,183,65,50

65,50,189,47

The question is how to compare the two in classic ASP in order to identify and return any values that exist in list 1 but that don't exist in list 2 bearing in mind that associative arrays aren't available.

E.g., in the above example I would need the return value to be 36,183

Thanks

A: 

Something like this (untested):

str1 = "36,189,47,183,65,50"
str2 = "65,50,189,47"

arr1 = Split(str1, ",")
arr2 = Split(str2, ",")

for i = 0 to UBound(arr1)  
   found = false
   for j = 0 to UBound(arr2)
      if arr1(i) = arr2(j) then
         found = true
      end if
   next   
   if found = false then
      Response.Write(arr1(i))
   end if
next
Benjol
Thanks for all of your suggestions. Neither method worked for me. I solved the problem by passing the lists into a SQL stored procedure and populated a couple of temporary tables from which I was able select the unique values and then insert the results into another table. This was always the end point of the task so it's no great loss to do it in SQL rather than in code and then pass the return values to the DB.Cheers
Reiwoldt
A: 

In order to solve this with regular expression you can use lookaheads (both positive and negative) and references, for example:

(zyx:~) % echo '36,189,47,183,65,50;65,50,189,47' | grep -oP '((?>(?<![^,;])[^,;]+))(?=.*;)(?!.*;(|.*,)\1(?=,|$))'
36
183

Other variant (works in PCRE but not in perl):

(zyx:~) % echo '36,189,47,183,65,50' | grep -oP '((?!(?<=,|^)65|50|189|47(?=,|$))(?<=,|^)[^,]+(?=,|$))'
36
183

Have no idea whether any of these works in asp.

ZyX