How can I translate \ to \\
i want to translate \ to \\For Example translate
"\\Pc1\source"
to
"\\\\Pc1\\source"
I wrote this
(vl-string-translate "\" "\\" "\\Pc1\source")
But there is a problem
The system does not accept "\" A single backslash in AutoLISP is an Escape Character, used to give an alternative meaning to characters which follow it (e.g. "\t" is the tab character). Therefore, before you pass the input string to an AutoLISP expression, you will first need to correctly represent the backslashes as literal backslashes within the string:
_$ (setq str "\\\\Pc1\\source")"\\\\Pc1\\source"Note that this will be printed with half the number of backslashes:
_$ (progn (princ str)(princ))\\Pc1\sourceNow, if you really wish to double the number of backslashes in the output string, there are a number of ways to accomplish this - here is one way:
_$ (vl-string-trim "\"" (vl-prin1-to-string str))"\\\\\\\\Pc1\\\\source"This output string will then be printed:
_$ (progn (princ (vl-string-trim "\"" (vl-prin1-to-string str)))(princ))\\\\Pc1\\source The string "\s" is 1 char length. You can check it.
(strlen "\s") -> 1(substr "\s" 1) -> "s"It is impossible to even set a variable to your source string.
So first thing is to check your variable. Try both (princ my_var) and (prin1 my_var), the real content of the variable is what the prin1 returns. Thanks for your description
I learned your training
I tried a lot . But it's not working properly on this example
\\Pc1\source
Intended character is deleted
\\\\Pc1source
There are only 2 ways you can enter this string :
(setq path "\\\\Pc1\\source") or
(setq path "//Pc1/source") even if your path is read from a (text)file lisp would automaticly translate "\\Pc1\source" to "\\\\Pc1\\source" so if you yourself enter this path manually you must use this string as shown above in your lisp code. If you let a user enter the path through a getstring you would get something like this :
Command: (setq path (getstring "\nPath : "))
Path : \\pc1\source
"\\\\pc1\\source"
gr. Rlx
The backslash character is not 'deleted' as it was never there in the first place - per my post above, a single backslash in AutoLISP is an Escape Character. If you want to represent a backslash in an AutoLISP string, you need to prefix it with another backslash to mark it as a literal backslash and not an Escape Character.
Please re-read my post above.
页:
[1]