title: How to remove duplicates from an array?
body: <p>I am trying to remove duplicate values from an array.</p>
  
  <p>I came across this solution:
  <a href="http://www.livio.net/main/asp_functions.asp?id=RemDups%20Function" rel="nofollow">http://www.livio.net/main/asp_functions.asp?id=RemDups%20Function</a></p>
  
  <p>It works fine if I hard code an array, via e.g.</p>
  
  <pre><code>theArray = Array("me@me.com","sid@sid.com","bob@bob.com","other@test.com","other@test.com","other@test.com")
  </code></pre>
  
  <p>The duplicates are removed via the test steps shown on the livio.net page:</p>
  
  <pre><code>'--- show array before modifications
  response.write "before:&lt;HR&gt;" &amp; showArray (theArray)
  
  '---- remove duplicate string values
  theArray = RemDups(theArray)
  
  '--- show the array with no duplicate values
  response.write "after:" &amp; showArray (theArray)
  </code></pre>
  
  <p>However, I am trying to remove duplicates from values which are entered into a textarea on a form.</p>
  
  <p>Assuming I've got the addresses in a standard format where they are comma separated, and are stored in a string called "whotoemail"</p>
  
  <p>So, "whotoemail" contains:</p>
  
  <pre><code>me@me.com,sid@sid.com,bob@bob.com,other@test.com,other@test.com,other@test.com
  </code></pre>
  
  <p>I tried declaring my array as:</p>
  
  <pre><code>theArray = Array(whotoemail)
  </code></pre>
  
  <p>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.</p>
  
  <p>I then thought, maybe the values need to be wrapped in speech marks, so I fudged a clunky way to do that:</p>
  
  <pre><code>testing = Split(whotoemail,",")
  loop_address = ""
  For i=0 to UBound(testing)
    loop_address = loop_address &amp; "," &amp; chr(34) &amp; trim(testing(i)) &amp; 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
  </code></pre>
  
  <p>So now my "whotoemail" string is wrapped in speech marks, just like when I hard coded the Array.</p>
  
  <p>But still the duplicate values are not removed.</p>
  
  <p>Is it not possible to dynamically set the values of the array when declaring the array?</p>
  
  <p>Or am I missing something obvious?</p>
  
  <p>Any advice would be hugely appreciated.</p>
  
  <p>Thanks!</p>