Author Topic: Find a string between delimiter1 and delimiter2  (Read 971 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Find a string between delimiter1 and delimiter2
« on: June 22, 2018, 06:03:12 AM »
Is this a good solution?
Code: [Select]
; (ALE_String_AfterBeforeDelimiter "123/45/1/2/999 H=9876 W - Foo1" "H=" " ") => "9876"
; (ALE_String_AfterBeforeDelimiter "123/45/1/2/999 H=9876 W - Foo1" "H=" "j") => "9876 W - Foo1"
; (ALE_String_AfterBeforeDelimiter "123/45/1/2/999 H=9876 W - Foo1" "x=" "j") => nil
;
; return nil if first Delimiter not found
; if second Delimiter not found return all string after first Delimiter
;
(defun ALE_String_AfterBeforeDelimiter (InpStr FrtDlm ScdDlm / SttPos EndPos)
  (if (setq SttPos (vl-string-search FrtDlm InpStr))
    (if (setq EndPos (vl-string-search ScdDlm InpStr (+ SttPos (strlen FrtDlm))))
      (substr InpStr (+ 1 SttPos (strlen FrtDlm)) (- EndPos SttPos (strlen ScdDlm) 1))
      (substr InpStr (+ 1 SttPos (strlen FrtDlm)))
    )
  )
)