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

vl-string-subst

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ProfWolfMan
1069 Views, 3 Replies

vl-string-subst

 

Hi,
Good Day!
Please see below.
Below requires in some file path handling process which i cannot change the requirment.
(they wants backslash and underscore followed by path). 
_$ (vl-string-subst "\_" "$temp" "$temppath")
"_path"
_$ (vl-string-subst "\\_" "$temp" "$temppath")
"\\_path"
How can i get result as "\_path"

 

Thanks & Regards,
G
3 REPLIES 3
Message 2 of 4


@ProfWolfMan wrote:

 

(they wants backslash and underscore followed by path). 
_$ (vl-string-subst "\_" "$temp" "$temppath")
"_path"
_$ (vl-string-subst "\\_" "$temp" "$temppath")
"\\_path"
How can i get result as "\_path"

 


_$ (setq p (vl-string-subst "\\_" "$temp" "$temppath"))
"\\_path"

That is actually the result you want:

 

_$ (vl-string->list p)
(92 95 112 97 116 104)

 

As you can see, the string only contains 6 characters. So use PRINC to print it out.

 

What is happening here is, that in Lisp the backslash is an escape character in strings, used to hide any special meaning

from the next character, for example when you want to have a quotation mark as a part of the string contents, instead of ending the string.

 

So, if you want to include a backslash in a string, it has to be escaped by another backslash in printed representation, but the string itself only contains one. PRINT and PRIN1 are intended to output a string in a form that produces the same string when read in by READ or LOAD, so they also show those escape characters. PRINC is intended for human-readable output, so it doesn't print the quotation marks and escape characters.

 

A sometimes usable alternative in file names is to use a slash as path separator instead of a backslash: AutoCAD and Windows also accept this in most usages, and it doesn't have the escape character behaviour.

 

--

 

 

Message 3 of 4
pbejse
in reply to: ProfWolfMan

thats right

 

the final result will be

"\_path"

 

try this on a text entity:

 

(entmod (subst (cons 1
  (vl-string-subst "\\_" "$temp" "$temppath"))
          (assoc 1 (setq ss (entget (car (entsel))))) ss))

 

Even if you're going to use this string to write to an external file

 

(write-line (vl-string-subst "\\_" "$temp" "$temppath")Filename)

 The result is still the same

\_path

 

Hope this will make you understand:

 

 

 

 

 

 

 

Message 4 of 4
ProfWolfMan
in reply to: ProfWolfMan

 

I understand now about behaviour of backslash character.
Enough and good explanation from both of you.
Thank you very much.

 

Thanks & Regards,
G

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

Post to forums  

Autodesk Design & Make Report

”Boost