Andyhon 发表于 2010-12-27 22:42:07

(setq str "DETAIL 15:21")

(setq strR (substr str (1+ (1+ (vl-string-search " " str))))
   Strnn (vl-string-search ":" strR)
      StrA (substr strR 1 Strnn)
      Strz (substr StrR (1+ (1+ Strnn)))
)

xiaobao02 发表于 2010-12-27 23:09:59

谢谢Andyhon的帮助!问题基本解决,就怕有些人输入“DETAIL 2:1”时不输空格,如真那样就没辙了,不过这样的结果已经很可以了!TKS!

Gu_xl 发表于 2010-12-27 23:12:09

改下即可
(apply 'strcat(mapcar 'chr (vl-remove-if '(lambda (x) (or (> x 58)(< x 48))) (VL-STRING->LIST "DETAIL 2:1"))))

Gu_xl 发表于 2010-12-28 08:45:55

回复 Gu_xl 的帖子

都已经是2:1了,你自己还分不开吗?

xiaobao02 发表于 2010-12-28 11:35:00

回复 Gu_xl 的帖子

(setq OK (strcat "Andyhon" "+" "Gu_xl")) 搞定了!
版主批評的是,即使不會,也不要只會等著拿來就用,要學會變通! 不就OK了嗎!!!
(setq str (apply 'strcat(mapcar 'chr (vl-remove-if '(lambda (x) (or (> x 58)(< x 48))) (VL-STRING->LIST "DETAIL 2:1")))) )

(setq Strnn (vl-string-search ":" str)
      StrA (substr str 1 Strnn)
      Strz (substr Str (1+ (1+ Strnn)))
)
此問題已完全解決!!
但如有更好,更簡短,歡迎再討論!!!

e2002 发表于 2010-12-28 11:57:57

要编程解决这种问题,必然你的字符串必须存在特定的规则,比如都是 Detail 开头, 后面接一个空格然后是 数字字符串:数字字符串.

用户选择后,如不符合的程序应该过滤掉.

原地踏步 发表于 2011-1-1 15:02:18

(mapcar 'chr (vl-remove-if '(lambda (x) (or (> x 58)(< x 48)))
(VL-STRING->LIST "DETAIL 15:21")))

("1" "5" ":" "2" "1")
分别将":"前与":"后的数字连起来即可。

lsjj 发表于 2011-1-1 18:15:00

(defun strim-ccm ( bk ax / b c)
(setq ax (vl-string-translate bk " " ax))
(while (setq c (vl-string-search " " ax))
    (setq b(cons (substr ax 1 c) b)
            ax (vl-string-trim " " (substr ax (1+ c)))
    )
)
(setq b (cons ax b))
(reverse b)
)

指令: (strim-ccm ":" "detail 15 : 21")
("detail" "15" "21")

指令: (strim-ccm ":" "detail 15:21")
("detail" "15" "21")
页: 1 [2]
查看完整版本: 請教:如何提取"DETAIL 2:1"中數字2和1