I am trying to remove duplicate values from an array.
I came across this solution: http://www.livio.net/main/asp_functions.asp?id=RemDups%20Function
It works fine if I hard code an array, via e.g.
theArray = Array("[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]")
The duplicates are removed via the test steps shown on the livio.net page:
'--- show array before modifications
response.write "before:<HR>" & showArray (theArray)
'---- remove duplicate string values
theArray = RemDups(theArray)
'--- show the array with no duplicate values
response.write "after:" & showArray (theArray)
However, I am trying to remove duplicates from values which are entered into a textarea on a form.
Assuming I've got the addresses in a standard format where they are comma separated, and are stored in a string called "whotoemail"
So, "whotoemail" contains:
[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
I tried declaring my array as:
theArray = Array(whotoemail)
Then running through the test steps - the duplicates are not removed. It doesn't seem to recognise that the array has been declared at all, or that it contains any values.
I then thought, maybe the values need to be wrapped in speech marks, so I fudged a clunky way to do that:
testing = Split(whotoemail,",")
loop_address = ""
For i=0 to UBound(testing)
loop_address = loop_address & "," & chr(34) & trim(testing(i)) & chr(34)
Next
' remove leading comma
left_comma = left(loop_address,1)
if left_comma = "," then
ttl_len = len(loop_address)
loop_address = right(loop_address,ttl_len-1)
end if
So now my "whotoemail" string is wrapped in speech marks, just like when I hard coded the Array.
But still the duplicate values are not removed.
Is it not possible to dynamically set the values of the array when declaring the array?
Or am I missing something obvious?
Any advice would be hugely appreciated.
Thanks!
splitfunction, but you are not aware of thejoinfunction. Look it up, it will make your life much simpler in combination with the answer of Ansgar Wiechers.