nonsmall 发表于 2009-1-5 13:34:00

[求助] 这个字符串怎么eval 值?

<p>下面的字符串去掉""后</p><p>"\"(setq folder \"\"d:\\\\\"\")\""</p><p>怎样得到变量folder ?</p><p>就是这个效果:(setq folder "d:\\")</p>

TANER 发表于 2009-1-5 15:24:00

(defun th-str-repl (curchar newchar str)<br/>&nbsp; (while (vl-string-search curchar str)<br/>&nbsp;&nbsp;&nbsp; (setq str (vl-string-subst newchar curchar str))<br/>&nbsp; )<br/>&nbsp; str<br/>)<br/>(setq str(th-str-repl "\"" "" "\"(setq folder \"\"d:\\\\\"\")\""))<br/>(setq l (read str))<br/>(list(car l)(cadr l)(vl-princ-to-string (last l)))<br/>;搞成了这样<br/>(SETQ FOLDER "D:\\\\")<br/>

nonsmall 发表于 2009-1-5 15:33:00

<p>楼上的结果好像是这个</p><p>"(setq folder d:\\\\)"</p>

TANER 发表于 2009-1-5 15:42:00

<p>不然!</p>

nonsmall 发表于 2009-1-5 15:56:00

本帖最后由 作者 于 2009-1-5 15:58:55 编辑 <br /><br /> <p>"\"(setq a (strcat \"\"new\"\" \"\"disk\"\"))\""</p><p></p><p>试试这个</p><p>规则是:"(setq a (strcat \"new\" \"disk\"))"中的一个"变成""</p><p>"(setq s \"ok\")"--&gt;"\"(setq s \"\"ok\"\")\""</p><p>我需要得到这样的效果</p><p>(eval (read "(setq a (strcat \"new\"&nbsp; \"disk\"))"))</p><p>返回 "newdisk"</p>

TANER 发表于 2009-1-5 16:01:00

没搞懂你的要求!sorry!

nonsmall 发表于 2009-1-5 16:26:00

<p>问题来源:</p><p>Excel保存为CSV格式的时候会产生上述问题</p><p>比如</p><p>(setq a (strcat "new" "disk" "d:\\"))</p><p>会存成</p><p>"(setq a (strcat ""new"" ""disk"" ""d:\\""))"</p><p>用Lisp读取结果是</p><p>"\"(setq a (strcat \"\"new\"\" \"\"disk\"\" \"\"d:\\\\\"\"))\""</p><p>如何还原?</p>

mccad 发表于 2009-1-5 17:34:00

<p>(defun string-subst (newchar curchar&nbsp; str)<br/>&nbsp; (while (vl-string-search curchar str)<br/>&nbsp;&nbsp;&nbsp; (setq str (vl-string-subst newchar curchar str))<br/>&nbsp; )<br/>&nbsp; str<br/>)</p><p>(defun aa()<br/>&nbsp; (setq temp "\"(setq a (strcat \"\"new\"\" \"\"disk\"\" \"\"d:\\\\\"\"))\"")<br/>&nbsp; (setq temp (string-subst "{$substring}" "\"\"" temp))<br/>&nbsp; (setq temp (string-subst "" "\"" temp))<br/>&nbsp; (setq temp (string-subst "\"" "{$substring}"&nbsp; temp))<br/>&nbsp; (read temp)<br/>&nbsp; )<br/></p>

nonsmall 发表于 2009-1-5 18:10:00

<p>姜还是老的辣!</p>

nonsmall 发表于 2009-1-5 18:16:00

<p>精简一下</p><p>(setq str "\"(setq a (strcat \"\"new\"\" \"\"disk\"\" \"\"d:\\\\\"\"))\"")<br/>(while (/= str (setq str (vl-string-subst "@" "\"\"" str))))<br/>(while (/= str (setq str (vl-string-subst "" "\"" str))))<br/>(while (/= str (setq str (vl-string-subst "\"" "@" str))))</p>
页: [1] 2
查看完整版本: [求助] 这个字符串怎么eval 值?