Author Topic: Get characters between "." and "," in a string... STUMPED  (Read 6227 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Get characters between "." and "," in a string... STUMPED
« Reply #30 on: September 20, 2016, 04:19:43 PM »
Here is one more, huge one and not so elegant as MP's or Evgeniy's, but test it... To me it looks fine...

Code: [Select]
(defun f-MR ( d s / d1 dl k ss c pl z l )
  (while (and (setq d1 (substr d 1 1)) (/= d1 ""))
    (setq d (substr d 2))
    (setq dl (cons d1 dl))
  )
  (foreach d1 dl
    (setq k -1 ss s)
    (while (and (setq c (substr ss 1 1)) (/= c ""))
      (setq ss (substr ss 2))
      (setq k (1+ k))
      (if (= c d1)
        (setq pl (cons k pl))
      )
    )
  )
  (setq pl (vl-sort pl '<))
  (foreach p pl
    (if (null z)
      (setq z 1)
    )
    (setq l (cons (substr s z (1+ (- p z))) l))
    (setq z (+ p 2))
  )
  (setq l (cons (substr s z) l))
  (vl-remove "" (reverse l))
)
« Last Edit: September 21, 2016, 12:43:39 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Hugo

  • Bull Frog
  • Posts: 422
Re: Get characters between "." and "," in a string... STUMPED
« Reply #31 on: September 21, 2016, 01:02:33 AM »
how are you going to assemble the list again.
Because yes is missing then the periods and commas

(setq d ":;,." s "686.TS.1,(686.18)")
("686" "TS" "1" "(686" "18)")

this is a little better not to the bar to be able to reassemble
("686" "." "TS" "." "1" "," "(" "686" "." "18" ")" )

 :thinking:

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Get characters between "." and "," in a string... STUMPED
« Reply #32 on: September 21, 2016, 03:03:33 AM »
Here is one more, huge one and not so elegant as MP's or Evgeniy's, but test it... To me it looks fine...
<>
Code: [Select]
(setq Keys ":;,123456789abcd" String "A1234567890absdfghjklòasdfghjklò:Bybqwuybqcuyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
(repeat 4 (setq String (strcat String ";" String)))

    (AM1 KEYS STRING).......1328 / 53.78 <fastest>
    (F-MR KEYS STRING).....71422 / 1 <slowest>

Comando: (F-MR KEYS STRING)
("A" "0" "s" "fghjklò" "s" "fghjklò" "By" "qwuy" "q" "uyqw" "iu" "Cs" "kjs" "kjs" "jk" "Duyyuwe" "ijiu" "A" "0" "s" "fghjklò" ...)

Comando: (AM1 KEYS STRING)
("A" "" "" "" "" "" "" "" "" "0" "" "s" "fghjklò" "s" "fghjklò" "By" "qwuy" "q" "uyqw" "iu" "" "" "" "" "" "" "" "" "Cs" "kjs" ...)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Get characters between "." and "," in a string... STUMPED
« Reply #33 on: September 23, 2016, 05:35:39 AM »
<>
The VLE functions are built into Bricscad or can be loaded into ACAD. (See attachment, also see link for supported vle-functions)

https://www.bricsys.com/bricscad/help/en_US/V16/DevRef/

I would suggest to change (member (car strlst) keylst) with (vl-position (car strlst) keylst)
Code: [Select]
(defun vle-string-split ( keys string / retlst idx len start keylst strlst )
    (setq idx 1 start 1 len (strlen string))
    (setq keylst (vl-string->list keys))
    (setq strlst (cons 0 (vl-string->list string)))
    (while (setq strlst (cdr strlst))
      (if (vl-position (car strlst) keylst) ; <<<
        (setq retlst (cons (substr string start (- idx start)) retlst)
              idx (1+ idx)
              start idx
        )
        (setq idx (1+ idx))
      )
    )
    (if retlst
      (reverse (cons (substr string start (1+ (- len start))) retlst))
      (list string)
    )
)