Author Topic: Equivalent to the VBA Split function in Vlisp  (Read 2620 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
Equivalent to the VBA Split function in Vlisp
« on: July 27, 2005, 08:53:32 AM »
Hello everybody,

Has somebody somewhere a lisp that does the same  as the split function in VBA, splitting a sting into parts at  a defined delimiter?

I would really like not to invent the wheel again.

Thanks in advance

Bernd

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Equivalent to the VBA Split function in Vlisp
« Reply #1 on: July 27, 2005, 09:02:19 AM »
Try this one:
Code: [Select]
;
; == Function MeString2List
; Converts a string to a list.
; Arguments [Type]:
;   Stg = String [STR]
;   Del = Delimiter pattern [STR]
; Return [Type]:
;   > Converted string [LIST]
;   > False if string empty
; Notes:
;   None
;
(defun MeString2List (Stg Del / DelLgt StrPos TmpLst TmpStr)
 (if (not (eq Stg ""))
  (progn
   (setq TmpStr Stg
         DelLgt (1+ (strlen Del))
   )
   (while (setq StrPos (vl-string-search Del TmpStr))
    (setq TmpLst (cons (substr TmpStr 1 StrPos) TmpLst)
          TmpStr (substr TmpStr (+ StrPos DelLgt))
    )
   )
   (setq TmpLst (cons TmpStr TmpLst))
   (reverse TmpLst)
  )
 )
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Equivalent to the VBA Split function in Vlisp
« Reply #2 on: July 27, 2005, 09:03:49 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Equivalent to the VBA Split function in Vlisp
« Reply #3 on: July 27, 2005, 09:04:57 AM »
Looks like Jürg got there first. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Amsterdammed

  • Guest
Equivalent to the VBA Split function in Vlisp
« Reply #4 on: July 27, 2005, 09:17:24 AM »
Thanks Jürg and Cab

I changed my mind and thought i must be able to do this myself

Code: [Select]

(defun split ( str del / nlist i )

  (While  (setq i(vl-string-position (ascii del) str))
    (setq nlist(append nlist (list (substr str 1 i)))
          str (substr str (+ i  2)))
    )
  (setq nlist (append nlist (list  str )))
       

)


Bernd