流_星 发表于 2022-6-24 10:26:26

字符串处理

大哥们,有这样一个字符串DC123456-15-11,或者DC123456-15-3,取DC123456-15,如何编写谢谢

自贡黄明儒 发表于 2022-6-24 10:39:38

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=107150&highlight=%BC%AF%D6%D0&_dsign=c7fd6a01

流_星 发表于 2022-6-24 10:48:35

自贡黄明儒 发表于 2022-6-24 10:39
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=107150&highlight=%BC%AF%D6%D0&_dsign=c7fd6a01

好资料,多谢多谢

xyp1964 发表于 2022-6-24 22:23:21


;; (abc "DC123456-15-11" "-15")
(defun abc (str sub / n)
(if (setq n (vl-string-search sub str))
    (substr str 1 (+ n (strlen sub)))
)
)

流_星 发表于 2022-6-25 07:10:21

xyp1964 发表于 2022-6-24 22:23


大哥请教一下,第一条是查询“”“-”所在的位置,第二条是所在位置加一对吧,那-15是动态的,是单数有可能也是双数,是不是就不能用这个函数了,谢谢

xiang19751218 发表于 2022-6-25 21:02:49

;(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)
)
页: [1]
查看完整版本: 字符串处理