乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 22|回复: 5

[编程交流] How can I translate \ to \\

[复制链接]

9

主题

31

帖子

24

银币

初来乍到

Rank: 1

铜币
43
发表于 2022-7-5 15:41:03 | 显示全部楼层 |阅读模式
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 "\"
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:01:15 | 显示全部楼层
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:
  1. _$ (setq str "\\\\Pc1\\source")"\\\\Pc1\\source"
Note that this will be printed with half the number of backslashes:
  1. _$ (progn (princ str)(princ))\\Pc1\source
Now, 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:
  1. _$ (vl-string-trim """ (vl-prin1-to-string str))"\\\\\\\\Pc1\\\\source"
This output string will then be printed:
  1. _$ (progn (princ (vl-string-trim """ (vl-prin1-to-string str)))(princ))\\\\Pc1\\source
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-5 16:09:50 | 显示全部楼层
The string "\s" is 1 char length. You can check it.
  1. (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.
回复

使用道具 举报

9

主题

31

帖子

24

银币

初来乍到

Rank: 1

铜币
43
发表于 2022-7-5 16:27:29 | 显示全部楼层
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
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 16:36:16 | 显示全部楼层
 
There are only 2 ways you can enter this string :
 
  1. (setq path "\\\\Pc1\\source")
or
  1. (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
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:42:54 | 显示全部楼层
 
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.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 21:08 , Processed in 0.691533 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表