明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: xiaobao02

[讨论] 請教:如何提取"DETAIL 2:1"中數字2和1

  [复制链接]
发表于 2010-12-27 22:42 | 显示全部楼层
(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)))
)

点评

此方法比較接近  发表于 2010-12-28 08:00

评分

参与人数 1金钱 +10 收起 理由
xiaobao02 + 10 测试了多种条件,可以满足使用要求

查看全部评分

 楼主| 发表于 2010-12-27 23:09 | 显示全部楼层
谢谢Andyhon的帮助!问题基本解决,就怕有些人输入“DETAIL 2:1”时不输空格,如真那样就没辙了,不过这样的结果已经很可以了!TKS!
发表于 2010-12-27 23:12 | 显示全部楼层
改下即可
(apply 'strcat  (mapcar 'chr (vl-remove-if '(lambda (x) (or (> x 58)(< x 48))) (VL-STRING->LIST "DETAIL 2:1"))))

点评

運行結果 “2:1” 不可分別為變量2和1  发表于 2010-12-28 08:01
发表于 2010-12-28 08:45 | 显示全部楼层
回复 Gu_xl 的帖子

都已经是2:1了,你自己还分不开吗?
 楼主| 发表于 2010-12-28 11:35 | 显示全部楼层
回复 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)))
)
此問題已完全解決!!
但如有更好,更簡短,歡迎再討論!!!
发表于 2010-12-28 11:57 | 显示全部楼层
要编程解决这种问题,必然你的字符串必须存在特定的规则,比如都是 Detail 开头, 后面接一个空格然后是 数字字符串:数字字符串.

用户选择后,如不符合的程序应该过滤掉.
发表于 2011-1-1 15:02 | 显示全部楼层
(mapcar 'chr (vl-remove-if '(lambda (x) (or (> x 58)(< x 48)))
(VL-STRING->LIST "DETAIL 15:21")))

("1" "5" ":" "2" "1")
分别将":"前与":"后的数字连起来即可。
发表于 2011-1-1 18:15 | 显示全部楼层
(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")
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-24 07:28 , Processed in 0.214780 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表