Author Topic: finding duplicates in one field  (Read 2976 times)

0 Members and 1 Guest are viewing this topic.

sub

  • Guest
finding duplicates in one field
« on: August 02, 2004, 06:11:30 AM »
hello all,

I want to find duplicates in a field those are separated with  :  
Ex:-    sub:sat:sub
mine is autocat map 2004. this thing is deals with object data.
Any Ideas :idea:

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
finding duplicates in one field
« Reply #1 on: August 02, 2004, 09:09:53 AM »
What do you want to do with them once found? Remove them make a list of them, etc.
TheSwamp.org  (serving the CAD community since 2003)

Anonymous

  • Guest
finding duplicates in one field
« Reply #2 on: August 03, 2004, 12:51:27 AM »
yes mark, i wnat to remove the duplicates

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
finding duplicates in one field
« Reply #3 on: August 04, 2004, 03:38:45 PM »
how about this.
Code: [Select]

;;; convert a delimted string to a list
;;; arguments
;;; str = string "one,two,three"
;;; del = string delimiter ","
;;; example
;;; (setq a "one,two,three")
;;; (setq b (conv-del-str-lst a ","))
;;; ("one" "two" "three")
(defun conv-del-str-lst (str del / tmp lst nlst tlst)

  ;; add an extra 'del' to the end of the string
  ;; before proccessing
  (setq tmp (substr str (strlen str) 1))
  (if (/= tmp del)
    (setq str (strcat str del))
    )
  ;; convert string to list of ints
  (setq lst (vl-string->list str)
        del (ascii del); del to int
        )

  (foreach item lst
           (cond ((/= item del)
                  (setq nlst (cons item nlst))
                  ); cond 1
                 ((= item del)
                  (setq tlst (cons (reverse nlst) tlst)
                        nlst nil
                        )
                  ); cond 2
                 )
           )
  ;; convert ints back to strings
  (if tlst (mapcar 'vl-list->string (reverse tlst)))
  )

;;; remove duplicates from a list
(defun remove-dups (lst / cntr nlst)
  (setq cntr 0)

  (while (< cntr (length lst))

         (cond
           ((not (member (nth cntr lst) nlst))
            (setq nlst (cons (nth cntr lst) nlst)
                  cntr (1+ cntr)
                  )
            )
           (T (setq cntr (1+ cntr)))
           )
         )

  (if nlst (reverse nlst))
  )

(setq a_str "gub:bub:sub:vub:dub:sub:cub:nub:sub:")
(setq a_lst (conv-del-str-lst a_str ":"))
-->("gub" "bub" "sub" "vub" "dub" "sub" "cub" "nub" "sub")
(setq final_list (remove-dups a_lst))
-->("gub" "bub" "sub" "vub" "dub" "cub" "nub")
TheSwamp.org  (serving the CAD community since 2003)

Anonymous

  • Guest
finding duplicates in one field
« Reply #4 on: August 05, 2004, 01:42:14 AM »
Thank you mark :D