Jump to content

custom format of angle units OR How to change letter in string?


Recommended Posts

Posted

I am trying to with no success to replace a resulting text of an angle annotation from format 0d00'00 to 0° 00' 00".

 

So I would like to replace the d within this string with the symbol "° " (alt+248 also with a space after it.)

 

My problem lies with not knowing how to loop through a string by letter and then subst it. I tried a substr method into a list with an increment counter but it errors.

 

Please help!

 

Thanks all

 

Stu

Posted

Two ways:

 

(vl-string-subst "°" "d" "0d00'00")

 

(setq result "" test "0d00'00")
(while (/= "" (setq x (substr test 1 1)))
 (setq result (strcat result (if (eq "d" x) "°" x)) test (substr test 2)))

 

Lee

Posted

Another:

 

(vl-list->string (subst 176 100 (vl-string->list "0d00'00")))

Posted
Two ways:

 

(vl-string-subst "°" "d" "0d00'00")

 

(setq result "" test "0d00'00")
(while (/= "" (setq x (substr test 1 1)))
 (setq result (strcat result (if (eq "d" x) "°" x)) test (substr test 2)))

 

Lee

 

 

 

Thanks Lee! Mystery solved:D

Posted
Two ways:

 

(vl-string-subst "°" "d" "0d00'00")

(setq result "" test "0d00'00")
(while (/= "" (setq x (substr test 1 1)))
 (setq result (strcat result (if (eq "d" x) "°" x)) test (substr test 2)))

Lee

Hi Lee could tell us more step how to apply this code, so i could use it too. i have no idea how?

:)

Posted

Oliver,

 

This is a standard function:

(vl-string-subst "°" "d" "0d00'00")

You can read up on how to use it in the Visual LISP Editor help files.

 

This:

 

(setq result "" test "0d00'00")
(while (/= "" (setq x (substr test 1 1)))
 (setq result (strcat result (if (eq "d" x) "°" x)) test (substr test 2)))

 

Cycles through each letter in the string "test", and if the letter is equal to that which you want to replace, then the replacement is concatenated to the result, else the test letter is concatenated.

 

Hope this helps,

 

Lee

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...