How would you replace "/" with "\"?

How would you replace "/" with "\"?

Anonymous
Not applicable
1,397 Views
7 Replies
Message 1 of 8

How would you replace "/" with "\"?

Anonymous
Not applicable

Hi,

 

How would you replace "/" with "\"? using vl-string-translate.

(vl-string-translate "/" "\" "/zzz")
to return "\zzz"?

 

0 Likes
Accepted solutions (1)
1,398 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

 

In LISP, backslalsh is the escape character so you have to double it (have a look at this topic).

(vl-string-translate "/" "\\" "/zzz") 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

Anonymous
Not applicable

Eventually, I`d like to reach the tab syntax "\t" and run it through lisp. SO I will need the backslash to be one character.

0 Likes
Message 4 of 8

_gile
Consultant
Consultant

You cannot use a single backslash, it have to associated with another character as control character ("\n", "\t") or as escape character ("\\", "\"").

It woulb be easier to help you if you provided a relevant example of what you want to achieve.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

Anonymous
Not applicable

I`d like to create a piece of Mtext which includes a tab. 

 

(setq str (vl-string-translate "/" "\" "1./tzzz"))

(setpropertyvalue (entlast) "Contents" str "")

 

Should result: 1. tab zzz

0 Likes
Message 6 of 8

_gile
Consultant
Consultant
Accepted solution

You can use:

(setq str (vl-string-subst "/t" "\t" "1./tzzz"))

But you should simply do:

(setq str "1.\tzzz")

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 8

Anonymous
Not applicable

Thank you Gilles!

I did a minor revision. (setq str (vl-string-translate "/" "\t" str)). It had an extra t there. Now it`s working like a charm! 🙂

0 Likes
Message 8 of 8

_gile
Consultant
Consultant

Keep in mind you have to consider "\n", "\t", "\\", "\"" as single characters.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub