Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating an array using split function

4 REPLIES 4
Reply
Message 1 of 5
zale-86
1146 Views, 4 Replies

Creating an array using split function

In asp I'd write:

arrFileName = Split(DrawingName, "_")

JobNumber = arrFileName(0)
DrawingTitle = arrFileName(1)

SheetNumber = arrFileName(2)

 

I'd like to do the same thing in lsp. I don't want to be limited to three fields so the split function is perfect.

 

Is there an equilivant?

 

TIA

 

 

 

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: zale-86


@zale-86 wrote:

In asp I'd write:

arrFileName = Split(DrawingName, "_")

JobNumber = arrFileName(0)
DrawingTitle = arrFileName(1)

SheetNumber = arrFileName(2)

 

I'd like to do the same thing in lsp. I don't want to be limited to three fields so the split function is perfect.

 

Is there an equilivant?

....


I don't know asp, but if I'm interpreting what you want to do correctly....

 

There have been many threads here about splitting or subdividing text strings around designated delimiting characters, and put the sub-strings into a list.  You can search and find lots of others, but for instance, my Message 8 here:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Extract-a-folder-name-within-dwgprefi...

 

Load up the (sdtol) function, and do this with it:

 

(setq

  arrFileName (sdtol (getvar 'dwgname) "_")

  JobNumber (nth 0 arrFileName)

  DrawingTitle (nth 1 arrFileName)

  SheetNumber (nth 2 arrFileName)

)

 

...plus whatever other "fields" your drawing name has, separated by underscores.

 

You might also need to add something to whack the ".dwg" off the end of the drawing name, but first see whether it does what you want otherwise.

Kent Cooper, AIA
Message 3 of 5

Command: (setq InfLst (ALE_String2List "JNumber_Title_SNumber" "_"))
("JNumber" "Title" "SNumber")

Command: (car InfLst)
"JNumber"

Command: (cadr InfLst)
"Title"

Command: (caddr InfLst)
"SNumber"

; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_String2List
;
; Version 1.00 - November 2001
;
; Description:
;   convert a string into a list
;
; Arguments:
;   InpStr = string [STR]
;   CarDlm = delimiter [STR] 1 character
;
(defun ALE_String2List (InpStr CarDlm / SttPos EndPos TmpLst)
  (setq
    CarDlm (ascii CarDlm)   SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
  )
  (while EndPos
    (setq
      TmpLst (cons (substr InpStr (1+ SttPos) (- EndPos SttPos)) TmpLst)
      SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
  )
  (reverse (cons (substr InpStr (1+ SttPos)) TmpLst))
)
; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_String_ToList
;
; Version 1.00 - 01/2010
;
; Description:
;   convert a string into a list of strings
;
; Arguments:
;   InpStr = string [STR]
;   CarDlm = delimiter [STR] 1 character
;   TrueFl = if nil remove dupes delimiter
;
; Examples:
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" T)
;  ("aaa" "vvv" "hhh" "" "yyy " "" "" "lll" "lll")
;
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" nil)
;  ("aaa" "vvv" "hhh" "yyy " "lll")
;
(defun ALE_String_ToList (InpStr CarDlm TrueFl / SttPos EndPos TmpLst TmpStr)
  (setq
    CarDlm (ascii CarDlm)   SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
  )
  (while EndPos
    (setq
      TmpStr (substr InpStr (1+ SttPos) (- EndPos SttPos))
      SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
    (and
      (or (/= TmpStr "") TrueFl)
      (setq TmpLst (cons TmpStr TmpLst))
    )
  )
  (if (or (/= (setq TmpStr (substr InpStr (1+ SttPos))) "") TrueFl)
    (reverse (cons TmpStr TmpLst))
    (reverse TmpLst)
  )
)

 

Marc'Antonio Alessi

http://alessi.xoom.it//alessi/Programmi.htm
(vl-string-translate "1234567890" "ie@mst.lan" "499825513610716")
2D Parametric for 2000-2013
Message 4 of 5
zale-86
in reply to: zale-86

Perfect. Thanks a lot

Message 5 of 5
microtecnologo
in reply to: zale-86

Hi Marc, I have tried your code and works perfectly, thanks a lot for sharing.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost