明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

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

再次求助怎么分离数字与符号?

  [复制链接]
发表于 2008-2-19 14:27:00 | 显示全部楼层
4.7;; 更改字符中包含 M=数字 的字符,将数字加1.5
(defun c:test1()
(setq str "2至M=56.5变M=3量M=.22"
      pat "(M)(=)(\\d{0,}\\.{0,1}\\d{1,})")
(setq lst (xxexp pat str "")) ;->("M=56.5" "M=3" "M=.22")
(setq lst2(mapcar '(lambda(x)(strcat "M=" (rtos(+ 1.5(distof(vl-string-subst "" "M=" x)))2 2)))lst))
 ;->("M=58.00" "M=4.50" "M=1.72")
(mapcar '(lambda(x y)(setq str (xxexpr x str y ""))) lst lst2)
str) ;-> "2至M=58.00变M=4.50量M=1.72"
4.8 ;; 将a=或d=开头的数字加一个数.
(defun c:test2()
   (setq str "测试a=2,d=3结果f=2,aa-3"
      add 1.75
      jd 2) ;精度
   (setq str2 (xxexpr "([a|d])(=)(\\d+)" str (strcat"$1$2(+ " (rtos add 2 jd) " $3)") "")) ;-> "测试a=(+ 1.75 2),d=(+ 1.75 3)结果f=2,aa-3"
   (setq as (mapcar '(lambda(x)(eval(read x))) (xxexp "(\\([^()]*\\))" str2  "")));->("(+ 1.75 2)" "(+ 1.75 3)")->(3.75 4.75)
   (mapcar '(lambda(x)(setq str2 (xxexpr "([a|d])(=)(\\([^()]*\\))" str2 (strcat "$1$2" (rtos x 2 jd)) "g"))) as)
   str2
) ;-> "测试a=3.75,d=4.75结果f=2,aa-3"
发表于 2008-2-19 16:19:00 | 显示全部楼层
http://zml84.blog.sohu.com/79553255.html
(vl-load-com)
;;;=============================================
;;;功能:字符串分割
;;;参数:STR ----欲分割的字符串,支持汉字
;;; LST ----分隔符表,大小写敏感
;;;日期:zml84 于 2008-02-19
;;;示例:(test "1N3.5(2)" '(("N")("(" ")")))
;;; ===>> ("1" "N" "3.5" "(2)")
;;;示例:(test "abc汉字2(1.5)" '(("汉""字")))
;;; ===>> ("abc" "汉字" "2(1.5)")
(defun TEST (STR LST / I LST2 LST_TMP STRI STR_TMP)
(setq LST2 '()) ;_存放结果的变量
(setq STR_TMP "")
(while (/= STR "")
(if (> (ascii(substr STR 1 1)) 159)
(setq STRI (substr STR 1 2)
STR (substr STR 3)
)
(setq STRI (substr STR 1 1)
STR (substr STR 2)
)
)
(if (setq LST_TMP (assoc STRI LST))
(progn
(if (/= STR_TMP "")
(setq LST2 (cons STR_TMP LST2)
STR_TMP ""
)
)
(cond
((= 1 (length LST_TMP))
(setq LST2 (cons STRI LST2))
)
((= 2 (length LST_TMP))
(if (setq I (vl-string-search (cadr LST_TMP) STR))
(setq LST2 (cons
(strcat STRI(substr STR 1 I) (cadr LST_TMP))
LST2
)
STR (substr STR (+ 1 I (strlen (cadr LST_TMP))))
)
(setq LST2 (cons STR LST2)
STR ""
)
)
)
)
)
(setq STR_TMP (strcat STR_TMP STRI) )
)
)
(if (/= STR_TMP "")
(setq LST2 (cons STR_TMP LST2))
)
(reverse LST2)
)

发表于 2008-2-19 22:26:00 | 显示全部楼层
jaminth发表于2008-2-18 22:24:00无痕斑主,能不能用正则表达式帮一下忙:我给出三种情况:----------------分离结果:(setq all \"125.36(T5)\")--------(setq sz \"125.36\");(setq wz \"(T5)\")(setq all \"585.360052\")--
  1. ;|实例:
  2. (setq pat "(.?T\\d+.?)|(\\d+\\.?\\d+)")
  3. (xxexp pat "125.36(T5)")
  4. ->返回:("125.36" "(T5)")
  5. (xxexp pat "[T6]585.360052")
  6. ->返回:("[T6]" "585.360052")
  7. (xxexp pat "{T8}125.36<T5>")
  8. ->返回:("{T8}" "125.36" "<T5>")
  9. |;
  1. ;|正则表达式分断字符串---by lxx|;
  2. (defun xxexp (pat str / end)
  3.   (vl-load-com)
  4.   (setq *xxvbsexp (vlax-get-or-create-object "VBScript.RegExp"))
  5.   (vlax-put *xxvbsexp 'Pattern pat)
  6.   (vlax-put *xxvbsexp 'Global -1)
  7.   (setq matches (vlax-invoke *xxvbsexp 'Execute str))
  8.   (vlax-for x matches (setq end (cons (vla-get-value x) end)))
  9.   (reverse end)
  10. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-6-19 17:35 , Processed in 0.264009 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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