Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

replace character

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Lupo76
2835 Views, 6 Replies

replace character

I searched google and forums but I could not find anything


There is a lisp function to replace all occurrences of a character within a string?

In short, as the Replace command in Visual Basic


For example, to replace all "x" to "*":
"34x59+60x3" -> "34*59+60*3


Thanks in advance

6 REPLIES 6
Message 2 of 7
pbejse
in reply to: Lupo76

One way

 

(defun rep  (n o str)
      (vl-list->string
            (mapcar '(lambda (x)
                           (if (= x (ascii o))
                                 (ascii n)
                                 x))
                    (vl-string->list str)
                    )
            )
      )

 

(rep "*" "x" "34x59+60x3")----> "34*59+60*3"

 

 

Message 3 of 7
martti.halminen
in reply to: Lupo76

_$ (vl-string-translate "x" "*" "34x59+60x3")
"34*59+60*3"

 

--


 

Message 4 of 7
pbejse
in reply to: martti.halminen


@martti.halminen wrote:

_$ (vl-string-translate "x" "*" "34x59+60x3")
"34*59+60*3"

 

--


Of course..

Silly me Smiley Very Happy

Message 5 of 7
Lupo76
in reply to: martti.halminen

Sorry for the delay of my reply!

I tried this solution but I do not know why, had not worked.I probably did something wrong ...

Thanks to all!

Message 6 of 7
scot-65
in reply to: Lupo76

Initialize once per session:

 

(vl-load-com)

 

???


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 7 of 7
Lupo76
in reply to: scot-65

Surely the problem was not that.

Is more likely that I had reversed the parameters Smiley Sad

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost