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
@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:
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.
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) ) )
Hi Marc, I have tried your code and works perfectly, thanks a lot for sharing.