明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 762|回复: 6

[经验] 字符串处理

[复制链接]
发表于 2022-6-24 10:26 | 显示全部楼层 |阅读模式
大哥们,有这样一个字符串DC123456-15-11,或者DC123456-15-3,取DC123456-15,如何编写谢谢
发表于 2022-6-24 10:39 | 显示全部楼层
 楼主| 发表于 2022-6-24 10:48 | 显示全部楼层
自贡黄明儒 发表于 2022-6-24 10:39
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=107150&highlight=%BC%AF%D6%D0&_dsign=c7fd6a01

好资料,多谢多谢
发表于 2022-6-24 22:23 | 显示全部楼层
  1. ;; (abc "DC123456-15-11" "-15")
  2. (defun abc (str sub / n)
  3.   (if (setq n (vl-string-search sub str))
  4.     (substr str 1 (+ n (strlen sub)))
  5.   )
  6. )
 楼主| 发表于 2022-6-25 07:10 | 显示全部楼层

大哥请教一下,第一条是查询“”“-”所在的位置,第二条是所在位置加一对吧,那-15是动态的,是单数有可能也是双数,是不是就不能用这个函数了,谢谢
发表于 2022-6-25 21:02 | 显示全部楼层
;(XD::String:RegExpS ".+(?=-)" "DC123456-15-3" "")->("DC123456-15")
;(XD::String:RegExpS ".+(?=-)" "DC123456-12-3" "")->("DC123456-12")
;(XD::String:RegExpS ".+(?=-)" "DC123456-2-3" "")->("DC123456-2")
(defun XD::String:RegExpS (pat str key / end keys matches x)
  (if (not *xxvbsexp)
    (setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
  )
  (vlax-put *xxvbsexp 'Pattern pat)
  (if (not key)
    (setq key "")
  )
  (setq key (strcase key))
  (setq        keys '(("I" "IgnoreCase")
               ("G" "Global")
               ("M" "Multiline")
              )
  )
  (mapcar
    '(lambda (x)
       (if (wcmatch key (strcat "*" (car x) "*"))
         (vlax-put *xxvbsexp (read (cadr x)) 0)
         (vlax-put *xxvbsexp (read (cadr x)) -1)
       )
     )
    keys
  )
  (setq matches (vlax-invoke *xxvbsexp 'Execute str))
  (vlax-for x matches (setq end (cons (vla-get-value x) end)))
  (reverse end)
)

点评

看着很厉害,先收藏需要是用  发表于 2022-6-26 09:31
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 06:21 , Processed in 0.199506 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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