SSGET字符串转义[支持中文及2021]
本帖最后由 CAD新军 于 2021-12-20 12:01 编辑;;脱编码
(defun lj:escapewildcards ( str / byte)
(if (and (< (getvar "LISPSYS") 1) (> (ascii (substr str 1 1)) 127))(setq byte 2)(setq byte 1))
(if (wcmatch str "*[-#@.*?~`[`,]*,*`]*")
(if (wcmatch str "[-#@.*?~`[`,]*,`]*")
(strcat "`" (substr str 1 1) (lj:escapewildcards (substr str 2)))
(strcat (substr str 1 byte) (lj:escapewildcards (substr str (1+ byte))))
)
str
)
)改编自Lee Mac的,但部分情况中文会出问题,比如“计算表8.1”不增加中文检测时,就会在“表”字打断的时候匹配上"?",然后中间加了一个转义符。cad2021后版本lispsys设置成1时,字符串是utf的,也不会有问题。具体应用可以参考我的一个脚本:
http://bbs.mjtd.com/thread-181402-1-1.html
当块名是“计算表8.1”时会出现问题(没办法选择),把原来的LM:escapewildcards替换就能正常使用。
(defun LM:escapewildcards ( str )
(if (wcmatch str "*[-#@.*?~`[`,]*,*`]*")
(if (wcmatch str "[-#@.*?~`[`,]*,`]*")
(strcat "`" (substr str 1 1) (LM:escapewildcards (substr str 2)))
(strcat (substr str 1 1) (LM:escapewildcards (substr str 2)))
)
str
)
)
LeeMac原来的是这样的。
_$ (LJ:ESCAPEWILDCARDS "计算表8.1")
"计算表8`.1"
_$ (LM:ESCAPEWILDCARDS "计算表8.1")
"计算盽?`.1"
_$ 这样可以搞中文啦!! 本帖最后由 1028695446 于 2021-12-25 19:15 编辑
不建议用这个,因为对中文字符处理不友好,建议用下面的这个函数(收集自明经论坛) 厉害,学习了
页:
[1]