Hey all,
I was given some tasks to achieve, one of them was to re-format some text that had various double/triple spaces back to a single space.
I couldn't quite figure out how to do this with the existing string-trim or char-replace methods - basically it would be removing all duplicates or all spaces. So I wrote a function which will process a list and remove any duplicates that are sequential. I thought I'd post the code here as I couldn't find sequential duplicate processing stuff easily, and also I bet there are some improvements to be made to my super-newbie code that I can learn from if anyone is willing to elaborate.
At the moment you can give it a list and a character to remove the sequential duplicates - in my case I'm using vl-string->list to convert the string to list and removing sequential 32s, then converting back, works like a charm. Improvements to be made could be the option to give 'nil' as a char in order to remove ALL sequential duplicates or to give it a list of chars to use, but I wasn't quite sure on the logic to be used there.
;; - DB:removeSeqDups
;; Removes sequential duplicates in a list, leaving the first occuring item in place
;;
;; - Inputs
;; [lst] - list of items
;; [char] - item to remove
;; - Outputs
;; [lst] - processed list of items
(defun DB:removeSeqDups
( in char
/ out prev
) (if (or (and (= item char
) (/= item prev
)) (/= item char))
)
)
)
(T nil)
)
)
_$ (DB:removeSeqDups '(1 1 2 3 4 4 4 5 6 6 7 7 7 7 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10) 9)
(1 1 2 3 4 4 4 5 6 6 7 7 7 7 8 8 8 8 8 9 10)