TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Eddie D. on September 13, 2016, 11:49:27 AM

Title: Get characters between "." and "," in a string... STUMPED
Post by: Eddie D. on September 13, 2016, 11:49:27 AM
OK guys, this has me stumped.

I have a text string where I need to get the string of characters between the LAST period before a comma and the comma.

For example:
string = "686.TS.1,(686.18)" I need to return the "1" between the period and comma.
or
string= "687B.101,(687B.TS.3)"  I need to return the "101" between the period and comma.

Anything after the comma is not needed.

This is probably simple, but I'm having a brain fart I guess.

Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 13, 2016, 12:00:50 PM
Code: [Select]
(defun _Whargarbl ( text / i j temp result )
    (and
        (setq i (vl-string-position (ascii ",") text nil t))
        (setq j (vl-string-position (ascii ".") (setq temp (substr text 1 i)) nil t))
        (setq result (substr temp (+ 2 j)))
    )
    result
)

(_Whargarbl "686.TS.1,(686.18)") >> "1"
(_Whargarbl "687B.101,(687B.TS.3)") >> "101"
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Eddie D. on September 13, 2016, 12:06:22 PM
AWESOME! Thanks!
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ronjonp on September 13, 2016, 12:29:49 PM
Here's another :)

Code - Auto/Visual Lisp: [Select]
  1. (defun foo (string / i)
  2.   (while (setq i (vl-string-search "." string))
  3.     (setq string (substr string (+ 2 i)))
  4.     (and (setq i (vl-string-search "," string)) (setq string (substr string 1 i)))
  5.   )
  6.   string
  7. )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Eddie D. on September 13, 2016, 03:49:08 PM
Thanks, Ronjon!
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 13, 2016, 04:45:23 PM
AWESOME! Thanks!

My pleasure. :)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: snownut2 on September 16, 2016, 12:23:43 PM
Or this...

Code - Auto/Visual Lisp: [Select]
  1. (defun parse-str ( str )  
  2.  (last(vle-string-split "." (car (vle-string-split "," str))))
  3.   )
  4.  

 (parse-str "686.TS.1,(686.18)") = "1"
 (parse-str "687B.101,(687B.TS.3)") = "101"

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/
 (https://www.bricsys.com/bricscad/help/en_US/V16/DevRef/)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 16, 2016, 12:40:21 PM
Quick and dirty alternative to vle-string-split that honors the argument signature and behavior (I think):

Code: [Select]
(defun _StringSplit ( keys string )
    ;;  (_StringSplit ":,." "Quote: This too, shall pass.")
    ;;  >> ("Quote" " This too" " shall pass")
    (mapcar 'vl-list->string
        (   (lambda ( codes delims / token result )
                (foreach x codes
                    (if (member x delims)
                        (setq result (cons token result) token  nil)
                        (setq token (cons x token))
                    )
                )
                (cons token result)
            )
            (reverse (vl-string->list string))
            (vl-string->list keys)
        )
    )
)

Edit: Revised to leave in leading/trailing nils as may be legit.
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 16, 2016, 01:41:49 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun f (s / F1)
  2.   (defun f1 (l i)
  3.     (cond ((member i l) (f1 (cdr (member i l)) i))
  4.           (l)
  5.     )
  6.   )
  7.   (vl-list->string (f1 (reverse (f1 (reverse (vl-string->list s)) (ascii ","))) (ascii ".")))
  8. )

test:

Code - Auto/Visual Lisp: [Select]
  1. (f "686.TS.1,(686.18)") ; "1"
  2. (f "687B.101,(687B.TS.3)") ; "101"
  3. (f "686.TS.1,(686.18),") ; "1"
  4. (f "687B.101,(687B.TS.3),") ; "101"
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 17, 2016, 04:29:44 PM
Love the efficiency / brevity EE. :)

On StringSplit ... another alt (not efficient, but no matter) simply because it's fun (and good for the grey muscle) to skin a cat multiple ways:

Code: [Select]
(defun _StringSplit ( delims text )
    ;;  (_StringSplit ":;," "A:B,C;D")
    ;;  >> ("A" "B" "C" "D")
    (   (lambda ( foo delims / result p )
            (while (setq p (car (vl-sort (mapcar 'foo delims) '>)))
                (setq
                    result (cons (substr text (+ 2 p)) result)
                    text   (substr text 1 p)
                )
            )
            (cons text result)
        )
        (lambda (d) (vl-string-position d text nil t))
        (vl-string->list delims)
    )
)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 19, 2016, 03:15:14 AM
my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun f (d s / i)
  2.   ;;(setq d ":;," s "A:B,C;D")
  3.   ;;(f d s)
  4.   (cond ((= d "") (list s))
  5.         ((setq i (vl-string-position (ascii d) s))
  6.          (append (f (substr d 2) (substr s 1 i)) (f d (substr s (+ 2 i))))
  7.         )
  8.         ((f (substr d 2) s))
  9.   )
  10. )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 19, 2016, 08:48:42 AM
[like]
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: MP on September 19, 2016, 10:46:16 AM
Another:

Code: [Select]
(defun _StringSplit ( keys string )
    ;;  (_StringSplit ":;," "A:B,C;D")
    ;;  >> ("A" "B" "C" "D")
    (   (lambda ( delims / i result )
            (repeat (setq i (strlen string))
                (if (member (vl-string-elt string (setq i (1- i))) delims)
                    (setq
                        result (cons (substr string (+ 2 i)) result)
                        string (substr string 1 i)
                    )
                )
            )
            (cons string result)
        )
        (vl-string->list keys)
    )
)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 19, 2016, 12:45:27 PM
...very rudimentary (I modified an old function)...
Code: [Select]
(defun ALE_String_ToListByKeys (InpStr KysStr / NewKys CarDlm SttPos EndPos TmpLst)
  (setq
    CarDlm (substr KysStr 1 1)  NewKys CarDlm
    NewKys (repeat (strlen KysStr) (setq NewKys (strcat CarDlm NewKys)))
    InpStr (vl-string-translate KysStr NewKys InpStr)
    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))
)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 19, 2016, 12:50:26 PM
new version:
Code - Auto/Visual Lisp: [Select]
  1. (defun f1 (d s)
  2.   (cond ((= d "") (read (strcat "(\"" s "\")")))
  3.         ((wcmatch s (strcat "*`" (substr d 1 1) "*")) (f1 d (vl-string-subst "\"\"" (substr d 1 1) s)))
  4.         ((f1 (substr d 2) s))
  5.   )
  6. )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Lee Mac on September 19, 2016, 06:06:03 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun f (d s / i)
  2.   ;;(setq d ":;," s "A:B,C;D")
  3.   ;;(f d s)
  4.   (cond ((= d "") (list s))
  5.         ((setq i (vl-string-position (ascii d) s))
  6.          (append (f (substr d 2) (substr s 1 i)) (f d (substr s (+ 2 i))))
  7.         )
  8.         ((f (substr d 2) s))
  9.   )
  10. )

This reminds me of the form of recursion used when implementing the quicksort algorithm - very good Evgeniy  :-)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 20, 2016, 02:46:38 AM
This reminds me of the form of recursion used when implementing the quicksort algorithm - very good Evgeniy  :-)

Hello Lee!
You have a great memory ;)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 20, 2016, 03:51:18 AM
Recursion is beautiful (very) but often is slower...
Code: [Select]
(defun AM1 (d s / n c p e l)
  (setq
    c (substr d 1 1)  n c
    n (repeat (strlen d) (setq n (strcat c n)))
    s (vl-string-translate d n s)
    c (ascii c)       p 0
    e (vl-string-position c s)
  )
  (while e
    (setq
      l (cons (substr s (1+ p) (- e p)) l)
      p (1+ e) e (vl-string-position c s p)
    )
  )
  (reverse (cons (substr s (1+ p)) l))
)
Code: [Select]
(setq Keys ":;," String "A:B,C;D")
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 131072 iteration(s):
    (AM1 KEYS STRING)................1703 / 1.83 <fastest>
    (AM1 KEYS STRING)................1704 / 1.82
    (_StringSplit3 KEYS STRING)......1766 / 1.76
    (_StringSplit3 KEYS STRING)......1781 / 1.75
    (_StringSplit1 KEYS STRING)......1875 / 1.66
    (_StringSplit1 KEYS STRING)......1906 / 1.63
    (F KEYS STRING)..................2359 / 1.32
    (F KEYS STRING)..................2360 / 1.32
    (_StringSplit2 KEYS STRING)......3015 / 1.03
    (F1 KEYS STRING).................3046 / 1.02
    (_StringSplit2 KEYS STRING)......3094 / 1
    (F1 KEYS STRING).................3109 / 1 <slowest>

(setq Keys ":;," String "A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:A:B,C;D:")
Elapsed milliseconds / relative speed for 16384 iteration(s):
    (AM1 KEYS STRING)................1438 / 4.42 <fastest>
    (AM1 KEYS STRING)................1453 / 4.38
    (_StringSplit1 KEYS STRING)......2235 / 2.85
    (_StringSplit1 KEYS STRING)......2235 / 2.85
    (_StringSplit3 KEYS STRING)......3266 / 1.95
    (_StringSplit3 KEYS STRING)......3312 / 1.92
    (_StringSplit2 KEYS STRING)......5671 / 1.12
    (_StringSplit2 KEYS STRING)......5750 / 1.11
    (F KEYS STRING)..................5797 / 1.1
    (F KEYS STRING)..................5813 / 1.09
    (F1 KEYS STRING).................6297 / 1.01
    (F1 KEYS STRING).................6359 / 1 <slowest>

(setq Keys ":;," String "A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
(repeat 4 (setq String (strcat String ";" String))
Elapsed milliseconds / relative speed for 16384 iteration(s):
    (AM1 KEYS STRING).................1532 / 12.07 <fastest>
    (AM1 KEYS STRING).................1609 / 11.49
    (F KEYS STRING)...................3437 / 5.38
    (F KEYS STRING)...................3453 / 5.35
    (_StringSplit2 KEYS STRING).......4516 / 4.09
    (_StringSplit2 KEYS STRING).......4609 / 4.01
    (_StringSplit3 KEYS STRING)......15906 / 1.16
    (_StringSplit3 KEYS STRING)......15906 / 1.16
    (F1 KEYS STRING).................16375 / 1.13
    (F1 KEYS STRING).................16454 / 1.12
    (_StringSplit1 KEYS STRING)......17609 / 1.05
    (_StringSplit1 KEYS STRING)......18485 / 1 <slowest>
Test order:
Code: [Select]
(Benchmark '(
(_StringSplit1 Keys String)
(_StringSplit2 Keys String)
(_StringSplit3 Keys String)
(AM1 Keys String)
(f   Keys String)
(f1  Keys String)
(_StringSplit1 Keys String)
(_StringSplit2 Keys String)
(_StringSplit3 Keys String)
(AM1 Keys String)
(f   Keys String)
(f1  Keys String)
)           ) 
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 20, 2016, 05:50:57 AM
Recursion is beautiful (very) but often is slower...

Hello Marc!
Yes!
Recursion is very slow.
The new version only for speed...
 :-)
Code - Auto/Visual Lisp: [Select]
  1. (defun f3 (d s / i)
  2.   (foreach a (vl-string->list d)
  3.     (while (setq i (vl-string-position a s)) (setq s (vl-string-subst "\"\"" (chr a) s)))
  4.   )
  5.   (read (strcat "(\"" s "\")"))
  6. )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: VovKa on September 20, 2016, 06:22:22 AM
:(
Code: [Select]
(f3 "." "A.B\"C.D")
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: VovKa on September 20, 2016, 06:26:43 AM
Recursion is beautiful (very) but often is slower...
speed of some functions depends on the length of both arguments
try increasing the length of delimiters also
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 20, 2016, 06:36:24 AM
Recursion is beautiful (very) but often is slower...

Hello Marc!
Yes!
Recursion is very slow.
The new version only for speed...
 :-)
Code - Auto/Visual Lisp: [Select]
  1. (defun f3 (d s / i)
  2.   (foreach a (vl-string->list d)
  3.     (while (setq i (vl-string-position a s)) (setq s (vl-string-subst "\"\"" (chr a) s)))
  4.   )
  5.   (read (strcat "(\"" s "\")"))
  6. )
>>> (read (strcat "(\"" s "\")"))
Read in some strings get error:
(read (strcat "(\"" "\".ABC" "\")")) =>; errore: punto in posizione non corretta nell'input
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 20, 2016, 07:07:30 AM
Recursion is beautiful (very) but often is slower...
speed of some functions depends on the length of both arguments
try increasing the length of delimiters also
New test:
Code: [Select]
(setq Keys ":;,123456789abcd" String "A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (AM1 KEYS STRING)................1781 / 9.61 <fastest>
    (AM1 KEYS STRING)................2329 / 7.35
    (_STRINGSPLIT1 KEYS STRING)......4547 / 3.76
    (_STRINGSPLIT1 KEYS STRING)......4890 / 3.5
    (_STRINGSPLIT3 KEYS STRING)......4922 / 3.48
    (_STRINGSPLIT3 KEYS STRING)......5468 / 3.13
    (F1 KEYS STRING).................6469 / 2.64
    (F1 KEYS STRING).................6750 / 2.53
    (F KEYS STRING)..................9844 / 1.74
    (F KEYS STRING).................10546 / 1.62
    (_STRINGSPLIT2 KEYS STRING).....16625 / 1.03
    (_STRINGSPLIT2 KEYS STRING).....17110 / 1 <slowest>



(setq Keys ":;,123456789abcd" String "A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
(repeat 4 (setq String (strcat String ";" String)))

Elapsed milliseconds / relative speed for 2048 iteration(s):
    (AM1 KEYS STRING)................1203 / 21.74 <fastest>
    (AM1 KEYS STRING)................1468 / 17.82
    (_STRINGSPLIT1 KEYS STRING)......4093 / 6.39
    (_STRINGSPLIT1 KEYS STRING)......4562 / 5.73
    (_STRINGSPLIT3 KEYS STRING)......5093 / 5.14
    (_STRINGSPLIT3 KEYS STRING)......5735 / 4.56
    (F KEYS STRING)..................9985 / 2.62
    (F KEYS STRING).................12672 / 2.06
    (_STRINGSPLIT2 KEYS STRING).....19579 / 1.34
    (_STRINGSPLIT2 KEYS STRING).....21281 / 1.23
    (F1 KEYS STRING)................24094 / 1.09
    (F1 KEYS STRING)................26157 / 1 <slowest>
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 20, 2016, 11:40:38 AM
new version, оnly for the sake of comparison, the speed...
Code - Auto/Visual Lisp: [Select]
  1. (defun f5 (d s / I L)
  2.     (foreach a (VL-STRING->LIST d) (setq l (cons (1+ (VL-STRING-POSITION a s)) l)))
  3.     (setq d 1
  4.           l (vl-sort l (function <))
  5.     )
  6.                                 (setq i d
  7.                                       d (1+ a)
  8.                                 )
  9.                                 (substr s i (- a i))
  10.                               )
  11.                     )
  12.                     l
  13.             )
  14.             (list (substr s d))
  15.     )
  16.   )

I do not like such a long code.  :?
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 20, 2016, 01:14:51 PM
new version, оnly for the sake of comparison, the speed...
<>
I do not like such a long code.  :?
I get error in second sample:

Code: [Select]
Comando: (setq Keys ":;," String "A:B,C;D")
"A:B,C;D"

Comando: (f5  Keys String)
("A" "B" "C" "D")

Comando: (setq Keys ":;,123456789abcd" String "A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
"A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu"

Comando: (f5  Keys String)
; errore: tipo di argomento errato: numberp: nil

Comando: (f1  Keys String)
("A" "" "" "" "" "" "" "" "" "0" "s" "fghjklò" "s" "fghjklò" "By" "qwuy" "quyqw" "iu" "" "" "" "" "" "" "" "" "Cs" "kjs" "kjs" "jk" "" "" "" "" "Duyyuwe" "" "" "" "" "" "ijiu")
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 20, 2016, 01:35:16 PM

I get error in second sample:

Code: [Select]
Comando: (setq Keys ":;,123456789abcd" String "A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
"A1234567890asdfghjklòasdfghjklò:Bybqwuybquyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu"

Comando: (f5  Keys String)
; errore: tipo di argomento errato: numberp: nil

Thank you!
I corrected the mistake...

Code - Auto/Visual Lisp: [Select]
  1. (defun f6 (d s / I L)
  2.     (foreach a (VL-STRING->LIST d) (setq l (cons (VL-STRING-POSITION a s) l)))
  3.     (setq d 1
  4.           l (vl-sort (vl-remove nil l) (function <))
  5.     )
  6.                                 (setq i d
  7.                                       d (1+ a)
  8.                                 )
  9.                                 (substr s i (- a i))
  10.                               )
  11.                     )
  12.                     l
  13.             )
  14.             (list (substr s d))
  15.     )
  16.   )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Lee Mac on September 20, 2016, 01:39:43 PM
Code: [Select]
_$ (f5 ";," "A;B,C;D,E")
("A" "B" "C;D,E")

_$ (f6 ";," "A;B,C;D,E")
("" ";" ",C;D,E")
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ElpanovEvgeniy on September 20, 2016, 02:08:12 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun f7 (d s / I L)
  2.   (foreach a (VL-STRING->LIST d)
  3.     (setq i 0)
  4.     (while (setq i (VL-STRING-POSITION a s (1+ i))) (setq l (cons (1+ i) l)))
  5.   )
  6.   (setq d 1
  7.         l (vl-sort (vl-remove nil l) (function <))
  8.   )
  9.                               (setq i d
  10.                                     d (1+ a)
  11.                               )
  12.                               (substr s i (- a i))
  13.                             )
  14.                   )
  15.                   l
  16.           )
  17.           (list (substr s d))
  18.   )
  19. )
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Lee Mac on September 20, 2016, 02:26:52 PM
Code: [Select]
_$ (f7 ";," ",A;B,C;D,E;")
(",A" "B" "C" "D" "E" "")

[sorry]
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi on September 20, 2016, 02:54:48 PM
f5 was faster...
Code: [Select]
(setq Keys ":;,123456789abcd" String "A1234567890absdfghjklòasdfghjklò:Bybqwuybqcuyqwbiu89897879,Csdkjsdkjsdjk3443;Duyyuwe878723ijiu")
(repeat 4 (setq String (strcat String ";" String)))

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (F5 KEYS STRING)..................1219 / 325.2 <fastest>
    (F5 KEYS STRING)..................1235 / 320.99
    (AM1 KEYS STRING)................20016 / 19.81
    (AM1 KEYS STRING)................20047 / 19.77
    (_STRINGSPLIT1 KEYS STRING)......67750 / 5.85
    (_STRINGSPLIT1 KEYS STRING)......68172 / 5.82
    (_STRINGSPLIT3 KEYS STRING)......84281 / 4.7
    (_STRINGSPLIT3 KEYS STRING)......84344 / 4.7 <slowest>

Elapsed milliseconds / relative speed for 2048 iteration(s):
    (AM1 KEYS STRING)...............1281 / 4.29 <fastest>
    (AM1 KEYS STRING)...............1313 / 4.19
    (F7 KEYS STRING)................2313 / 2.38
    (F7 KEYS STRING)................2390 / 2.3
    (_STRINGSPLIT1 KEYS STRING).....4188 / 1.31
    (_STRINGSPLIT1 KEYS STRING).....4375 / 1.26
    (_STRINGSPLIT3 KEYS STRING).....5390 / 1.02
    (_STRINGSPLIT3 KEYS STRING).....5500 / 1 <slowest>
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: ribarm 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))
)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Hugo 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:
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi 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" ...)
Title: Re: Get characters between "." and "," in a string... STUMPED
Post by: Marc'Antonio Alessi 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/
 (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)
    )
)