Author Topic: If possible help with the conversion "13204.74087\\P16224.7943\\P2.56"  (Read 1781 times)

0 Members and 1 Guest are viewing this topic.

HOSNEYALAA

  • Newt
  • Posts: 103
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

ronjonp

  • Needs a day job
  • Posts: 7527
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
« Last Edit: August 27, 2019, 11:51:56 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
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.  

HOSNEYALAA

  • Newt
  • Posts: 103
Thank you so much
ronjonp

Tharwat


The solution is good
And it works great
Thank you

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
You're welcome anytime.