Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2004
    Posts
    22

    Unanswered: compare strings to find uniques

    Hi,
    in ASP, is there a smart way to compare strings in this manner?

    I have 5 codes. I want to find out how many unique ones there are.

    WU7TD
    TYBSU
    MAWVR
    WU7TD
    ASKRF

    I could use InStr for each combination, but this gets complex only after a few. I could use DISTINCT if were an SQL query, but I need to do it within ASP.

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    There is nothing built in that would do this for you, you would need to write something up, wouldn't be too hard though...

    How are these codes stored in your ASP code? is it a comma delimitered string or something?

  3. #3
    Join Date
    Jan 2004
    Posts
    22
    Hi rokslide,

    They are originally in separate fields in the same record in an MSSQL table, but I was trying to handle them solely within the ASP rather than make another call to the database.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by full monty View Post
    ... rather than make another call to the database.
    so you're already calling the database to get these codes?

    please show your query for this, as it is likely that it can be modified, so that you wouldn't have to write any ASP code at all
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2004
    Posts
    22
    I know it's bad practice, but I'm using SELECT * and getting just one record. (But in my defence, I am using most of the fields to display on my web page.)

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    just one record is producing these codes which might contain duplicates?

    i'm getting confuseder as we go...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    I suspect the database has something like...

    Code:
    RowId    Cust1Id    Cust1Code    Cust2Id    Cust2Code    Cust3Id    Cust3Code    Cust4Id    Cust4Code
        1          1        WU7TD          2        TYBSU          3        MAWVR          4        WU7TD

  8. #8
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If this is ASP.NET, then you can avail yourself of distinct with LINQ. If this is classic ASP, then you're talking about an algorithm 101 question. Will you always have 5 or so records? If so then the approach doesn't really matter. If not then you need to make some optimization decisions.


    If your table structure is as rokslide is suggesting, then you "fix" this issue by using an actual relational model in the database.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  9. #9
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Assuming you don't want to or can not fix your database... this script might help you...

    Code:
    <%
    Dim duplicateStrings
    duplicateStrings = Array("WU7TD","TYBSU","MAWVR","WU7TD","ASKRF")
    
    Dim distinctStrings()
    Redim distinctStrings(0)
    
    for each entry in duplicateStrings
        
        Response.Write(entry & " ")
        matches = UBound(Filter(distinctStrings,entry))
    
        if(matches<0) then
            distinctStrings(Ubound(distinctStrings)) = entry
            Redim Preserve distinctStrings(UBound(distinctStrings)+1)
        end if
    
    next
    
    Redim Preserve distinctStrings(UBound(distinctStrings)-1)
    
    response.write("<br><br>")
    
    for each dis_entry in distinctStrings
        response.write("- " & dis_entry & "<br>")
    next
    
     %>
    Basically it looks though an array of strings, if the string is not in the distinct list (another array) it adds it to the distinct list.

    HTH

  10. #10
    Join Date
    Jan 2004
    Posts
    22
    just wanted to say Thank You (belatedly). This solution did indeed work.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •