String to decimal

String to decimal

k005
Advisor Advisor
1,319 Views
15 Replies
Message 1 of 16

String to decimal

k005
Advisor
Advisor

Hello to everyone

How can I convert a text expression to decimal format?

sample:

 

(setq criteria1 (dos_getstring "Explode" "Character to search for explosion :"))

criteria1= Φ

but criteria1=63 should be.

(setq criteria (chr criteria1))...........(setq criteria (chr 63))

how can I do that ?

0 Likes
Accepted solutions (1)
1,320 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor
(defun c:StrToDec ( / f n strin)
(defun replace-n  (new n lst /)
    (mapcar '(lambda (a)
                   (if (= (setq n (1- n)) -1)
                         new
                         a))
            lst))
(setq f '(83 116 114 105 110 103 32))  
(setq n -1)
(setq strin (mapcar (function
(lambda (a b c) (setq d    nil n    (1+ n)
symb (if (minusp a) 1- 1+))
(repeat (abs a)
 (setq d (cons
               (setq f    (replace-n
                                (setq b (symb b))
                                n
                                f))
               d)))
	   )
	) '(-15 -15 -15 0 1 -6 76)
	f
'(68 101 99 105 109 97 108))
    )
(textscr)
(foreach
     itm
     (cons '(83 116 114 105 110 103)
           (append (apply 'append (mapcar 'reverse strin))
                   '((68 101 99 105 109 97 108))))
    (print (vl-list->string itm))
    (princ)
    )
(princ "<<---There you go!! ")
(princ)
    )

command: StrToDec

 

Message 3 of 16

k005
Advisor
Advisor

@pbejse 

 

Hello my friend

I want to call it as a function.

 

This way it was not controlled.

 

(setq criteria1 (dos_getstring "Explode" "Patlama için aranacak Karakter :"))

 

(setq criteria ( chr (strcat StrToDec criteria1)))

0 Likes
Message 4 of 16

pbejse
Mentor
Mentor

@k005 wrote:

I want to call it as a function.

...

(setq criteria ( chr (strcat StrToDec criteria1)))

...

 

StrToDec is meant as a joke @k005, and not to be taken seriously 🙂

 

Besides I dont have  DOSLib - McNeel  installed on my workstation. 

What I see here is not 63 but 934

 

(ascii "Φ")-- >934
(chr 934) --> "Φ"

 

 What are trying to do anyway?

 

 

0 Likes
Message 5 of 16

k005
Advisor
Advisor

@pbejse 

 

And that's where the problem is...

Φ «--- While this mark is visible in the drawing., Autolisp Editor also
? «---- sign. It appears as a

 

I thought I could pass this problem by converting it to decimal. and even ? The decimal value of 63 is equivalent.


So the trouble here is that this sign misleads us: Φ = U+03A6 

 

this is how it is...

0 Likes
Message 6 of 16

pbejse
Mentor
Mentor

Works here:

Attribute

 

(Vla-put-textstring (Vlax-ename->vla-object (car (nentsel))) (chr 934))

 

Text

 

(Vla-put-textstring (Vlax-ename->vla-object (car (nentsel))) (strcat "Linkin "(chr 934) " Park"))
(Vla-put-textstring (Vlax-ename->vla-object (car (nentsel))) (strcat "Linkin \\U+03A6 Park"))

 

 

pbejse_0-1632570360428.png

 

 

0 Likes
Message 7 of 16

Sea-Haven
Mentor
Mentor

(chr 63) is the question mark. It is less than 128 the default characters that are in most fonts, Yours is in excess of 128 extended character set. If you go Windows Fonts can look at that character, I found it Arial Greek Capital letter Phi. It depends on what font your using. 

Message 8 of 16

k005
Advisor
Advisor

@pbejse 

@Sea-Haven 

 

As seen in the picture.

 

I want the decimal code of the character entered here.

 

then the problem will be solved...

 

 

0 Likes
Message 9 of 16

pbejse
Mentor
Mentor

Since I dont have Dos_LIB i'm note sure what works and what doesnt

You can always try ALT+232 as Φ ,that should work.

But i'm not sure that's not what you're referring to. like i said 934 works here [2022 Autocad and VSCode ]

 

0 Likes
Message 10 of 16

k005
Advisor
Advisor

 

now my friend;

 

can we do this; Whatever is entered into the textbox, it will give me a decimal value in a variable.

 

can we do this?

 

0 Likes
Message 11 of 16

pbejse
Mentor
Mentor
Accepted solution

@k005 wrote:

can we do this; Whatever is entered into the textbox, it will give me a decimal value in a variable.


Not sure how in DOS_Lib textbox

 

If its a single character then use chr/ascii function but if you input something like that symbol "Φ" it the result would be more than one character. in 2022 it will be 934, but in lower version its something else "¦"

 

(defun c:Demo ()
  (if
    (setq DFS (lisped "Enter One Character to convert to decimal"))
     (cond
       ((numberp DFS))
       ((= (strlen DFS) 1) (print (ascii DFS)))
       ((print (vl-string->list DFS)))
     )
  )(princ)
)

 

 

Message 12 of 16

k005
Advisor
Advisor

 

Yes ! Just as I predicted. Thank you very much. it worked.

 

Ok. Again a great work. my friend. Thanks.

0 Likes
Message 13 of 16

pbejse
Mentor
Mentor

@k005 wrote:

Yes ! Just as I predicted. Thank you very much. it worked.


That's good to know, do let us know how you it goes with the Dos_Lib thingy.

And you are welcome. 🙂

 

Cheers

 

0 Likes
Message 14 of 16

k005
Advisor
Advisor

 

wait a minute... things got messy... it just worked but now it doesn't. 😞

0 Likes
Message 15 of 16

k005
Advisor
Advisor

I couldn't. I'll look into this later.

 

Doslib :

 

http://wiki.mcneel.com/doslib/home

0 Likes
Message 16 of 16

Kent1Cooper
Consultant
Consultant

[ never mind ]

Kent Cooper, AIA