• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

extract characters from strings

  • Thread starter Thread starter Dr.Lube
  • Start date Start date

Dr.Lube

Guest
Hello, everyone!

are looking for a way to extract some characters from strings.
I tried to googlare a little but all I find are commands that are not going (probabilmetne use another compiler? ).
HTML:
http://cl-cookbook.sourceforge.net/strings.html
and many other sites that talk about common lisp, which I thought was what we use. .

In any case I should extract from "3phi12 sup." the "3" and "12".

Can anyone give me a tip?



Thank you very much,
dennis
 
Okay, I found the answer maybe:
common lisp is something general, the one applied to autocad is called autolisp!

here anyway there is something to manipulate
HTML:
http://www.jefferypsanders.com/autolispintr_string.html
 
The function you're looking for is substr.
we say that stringatot is the variable that contains your string "3phi12 sup."
the function becomes
(setq sub1)substr stringatot 1 1)) that will return "3"
(setq sub2)substr stringatot 5 2)) that will return "12"
 
The function you're looking for is substr.
exact, however, since the number of digits could change, if the standard string was "numphidiam ecc." you could extract the two values in this way:
Code:
(setq n (vl-string-search "phi" str))
(setq num (substr str 1 n))
(setq diam (substr str (+ 4 n) 1))
)))
(setq diam (tight diam x))
)
ad esempio:
(setq str "10phi14 sup.") return:
"10"
"14" day
(setq str "8phi12 sup.")return:
in a "8"
"12" day
(setq str "6phi8 sup.")return:
"6"
diam "8"
 
if diam has more than two digits, it doesn't work anymore...:smile:
Code:
(setq nnum (vl-string-search "phi" str))
(setq ndiam (vl-string-search " sup." str))
(setq num (substr str 1 nnum))
(setq diam (substr str (+ 4 nnum) (- ndiam (+ 3 nnum))))
remaining that the strings "phi" and "sup." are always the same, otherwise you have to add other conditions.
 
further compression:
Code:
(setq str (vl-string-right-trim " sup." str))
(setq num (substr str 1 (vl-string-search "phi" str)))
(setq diam (substr str (+ (vl-string-search "phi" str) 4)(strlen str)))
 
if diam has more than two digits, it doesn't work anymore...
They are reinforced concrete bars, not a sewer. :tongue::wink

remaining that the strings "phi" and "sup." are always the same, otherwise you have to add other conditions.
In fact, it must be clear, the important thing is that "phi" is interposed between the two numerical values, while "sup." is influential. :smile:


p.s. [OTmode ON] I'm already "training"...:wink: [OTmode OFF]
 
Well, my stringed program is "general purpose" so instead of mm you can also use cabbage, beans, potatoes or astronomical units :tongue:

already, we need clarification, otherwise "phi" becomes "_phi ", " .phi", "-phi" and all possible variations. . .
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top