scubastu Posted November 29, 2009 Posted November 29, 2009 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 Quote
Lee Mac Posted November 29, 2009 Posted November 29, 2009 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 Quote
Lee Mac Posted November 29, 2009 Posted November 29, 2009 Another: (vl-list->string (subst 176 100 (vl-string->list "0d00'00"))) Quote
scubastu Posted November 30, 2009 Author Posted November 30, 2009 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 Quote
oliver Posted November 30, 2009 Posted November 30, 2009 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? Quote
Lee Mac Posted November 30, 2009 Posted November 30, 2009 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 Quote
Recommended Posts
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.