I need a to take a delimited list and remove all duplicate instances.

Simpler code does not always mean faster, it depends on the cost of the individual operations, and in many cases, on the expected structure of the input parameters. However, here is a simpler way to do what you want (off the top of my head, untested, may contain bugs, your mileage may vary)

Function removeDuplicates(sourceString as string,delim as string) As string

  // remove duplicate elements from sourceString

  dim i as Integer
  dim cString,finalString,token as String

  finalString = ""

  // add a delimiter to the end of the source string

  cString = sourceString + ","

  // find the first delimiter in the string

  i = cString.indexOf(delim)

  // while there are delimiters remaining in the string

  while (i <> 0)

    // extract the first token and delimiter

    token = cString.left(i)

    // add to the final string

    finalString = finalString + token

    // remove all the matching tokens+delimiters from the source string

    cString.replaceAll(token,"")

    // find the next delimiter

    i = cString.indexOf(delim)

  wend

  // result has an extra delimiter, so we must remove it

  return finalString.left(finalString.len-1)

End Function

-----

Robert Woodhead - CEO - AnimEigo


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to