TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HOSNEYALAA on August 27, 2019, 10:32:51 AM

Title: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"
Post by: HOSNEYALAA on August 27, 2019, 10:32:51 AM
Hello all
If I have this sentence

"13204.74087\\P16224.7943\\P2.56"

How can i turn it into

(13204.74087 16224.7943 2.56)

Thanks in advance
Title: Re: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"
Post by: ronjonp on August 27, 2019, 11:18:43 AM
Something like this:
Code - Auto/Visual Lisp: [Select]
  1. (read (strcat "(" (vl-string-translate "\\P" "  " "13204.74087\\P16224.7943\\P2.56") ")"))

Or do a search for 'parse string' .. there are numerous examples.

Probably most used: http://www.lee-mac.com/stringtolist.html
Title: Re: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"
Post by: Tharwat on August 27, 2019, 11:25:34 AM
Hi,

Your string must have been retrieved from Mtext object.  :wink: so you can use the following function:
Code - Auto/Visual Lisp: [Select]
  1. (defun _peelstring (string del / str pos lst)
  2.   ;; Tharwat - date: 07.Nov.2015        ;;
  3.   (while (setq pos (vl-string-search del string 0))
  4.     (setq str    (substr string 1 pos)
  5.           string (substr string (+ pos (1+ (strlen del))))
  6.     )
  7.     (and str (/= str "") (setq lst (cons str lst)))
  8.   )
  9.   (and string (/= string "") (setq lst (cons string lst)))
  10.   (reverse lst)
  11. )

The return would be in a string format:

Code - Auto/Visual Lisp: [Select]
  1. (_peelstring "13204.74087\\P16224.7943\\P2.56" "\\P")
  2.  
Title: Re: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"
Post by: HOSNEYALAA on August 28, 2019, 01:57:23 AM
Thank you so much
ronjonp

Tharwat


The solution is good
And it works great
Thank you
Title: Re: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"
Post by: Tharwat on August 28, 2019, 04:58:28 AM
You're welcome anytime.