| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-17-11, 14:54
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 22
|
|
|
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.
|
|

01-18-11, 18:19
|
|
Registered User
|
|
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
|
|
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?
|
|

01-18-11, 20:13
|
|
Registered User
|
|
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.
|
|

01-18-11, 20:16
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
Originally Posted by full monty
... 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
|
|

01-18-11, 21:04
|
|
Registered User
|
|
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.)
|
|

01-18-11, 21:52
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
just one record is producing these codes which might contain duplicates?
i'm getting confuseder as we go...
|
|

01-18-11, 22:34
|
|
Registered User
|
|
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
|
|
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
|
|

01-18-11, 23:47
|
|
Purveyor of Discontent
|
|
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
|
|
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.
|
|

01-19-11, 16:08
|
|
Registered User
|
|
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
|
|
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
|
|

02-12-11, 03:20
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 22
|
|
just wanted to say Thank You (belatedly). This solution did indeed work.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|