TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mgreven on February 24, 2012, 03:29:40 AM
-
Hello,
Maybe i ask a stupid question, but is there a way to replace double backslashes in a string?
I am getting a result from the Filefind routine "C:\\TEMP\\temp.txt" which i want to transform into "C:\TEMP\temp.txt".
I tried it with the vl-string-subst command but i cannot give a single "\" to the routine?
Regards,
Marco
-
In LISP (and other languages), the backslash is used as an Escape Character (http://en.wikipedia.org/wiki/Escape_character) to give a sequence of characters an alternative meaning, e.g.:
"\n" = new line character
"\t" = tab character
"\r" = carriage return
...
Hence, to display a literal backslash you need to mark it as a literal by prefixing it with another backslash ("\\").
This means that a double backslash in LISP is interpreted as a single backslash.
Consider this example program:
(setq str
(getstring t
"\nEnter a String with some Backslashes: ")) (princ "\nString in LISP format: ")
(princ "\nString when printed: ") )
To demonstrate:
Command: test
Enter a String with some Backslashes: a\b\c
String in LISP format: "a\\b\\c"
String when printed: a\b\c
-
Thanks for your respons...