Author Topic: Capturing the last positions of text to a variable  (Read 2089 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Capturing the last positions of text to a variable
« on: May 07, 2013, 07:41:20 AM »
Hi, :-)

This lisp returns me the file name without the dwg

(setq arq (getvar "dwgname")) ; Catch filename
(setq comp (strlen arq)) ; take the length of the file name
(Setq comp (- (strlen arq)4)) ; length of the same name 4
(Setq text (substr arq 1 comp))

I need to get only the review of lisp, and I know that without the last 4 texts (. Dwg), revision (Rxx) is the last three letters,

How do I get to capture them?

Thank in advance

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Capturing the last positions of text to a variable
« Reply #1 on: May 07, 2013, 07:54:11 AM »
Code: [Select]
(setq str (vl-filename-base (getvar 'dwgname)))
(substr str (- (strlen str) 2))

bruno_vdh

  • Guest
Re: Capturing the last positions of text to a variable
« Reply #2 on: May 07, 2013, 08:10:20 AM »
Code: [Select]
(substr (setq str (getvar 'dwgname)) (- (strlen str) 6) 3)

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Capturing the last positions of text to a variable
« Reply #3 on: May 07, 2013, 08:57:05 AM »
Code: [Select]
(substr (setq str (cadr (fnsplitl (getvar 'dwgname)))) (- (strlen str) 2))
Code: [Select]
(substr (setq str (getvar 'dwgname)) (- (vl-string-position 46 str) 2) 3)
« Last Edit: May 07, 2013, 09:02:32 AM by Lee Mac »

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Capturing the last positions of text to a variable
« Reply #4 on: May 07, 2013, 11:58:32 AM »
Thank you so much Lee and Bruno!

 :lol:
Regards
Fabricio