- 积分
- 64507
- 明经币
- 个
- 注册时间
- 2010-5-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 自贡黄明儒 于 2013-8-14 14:39 编辑
;;85.1 [功能] 字符串分割
;;http://www.mjtd.com/function/info-129-216.html,有修改 黄明儒 2013年8月9日
;;(setq str "100,,23456.876,345.456," delim ",")
(defun parse1 (str delim / LST POS)
(while (setq pos (vl-string-search delim str))
(setq lst (cons (substr str 1 pos) lst)
str (substr str (+ pos 2))
)
)
(if (> (strlen str) 0)
(setq lst (cons str lst))
)
(reverse lst)
)
;;85.2 [功能] 字符串分割
;;http://www.mjtd.com/function/info-129-444.html,修改xl:read->biao 黄明儒 2013年8月9日
(defun parse2 (str delim / LST POS)
(while (setq pos (vl-string-search delim str))
(setq lst (append lst (list (substr str 1 pos))))
(setq str (substr str (+ 2 pos)))
)
(if (> (strlen str) 0)
(append lst (list str))
lst
)
)
;|
;;http://www.xdcad.net/forum/thread-669166-1-2.html By XDSoft
功能 对字符串进行正则表达式匹配测试.
pat = 正则表达式模式 ,对应vbs正则表达式的模式(expression)。说明: \\号要用\\\\替代.
str = 字符串
key = \"i\" \"g\" \"m\" , \"i\"不区分大小写(Ignorecase),\"g\"全局匹配(Global).
\"m\"多行模式(Multiline),以上几个关键字可以组合使用,或用 \"\".
返回: 返回匹配的字符列表,或无一匹配返回nil
|;
(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)
)
;;85.3 [功能] 字符串分割 By st788796
;;这是一个很万能的分割法,只不过delim写法复杂
;;示例:,分割(parse3 "A 3.2测,试5.66D" "[^,]+");;("A 3.2测" "试5.66D")
;;空格分割(parse3 "A 3.2测,试5.66D" "[^\\s]+");;("A" "3.2测,试5.66D")
;;中英文空格(parse3 "A 3.2测,试5.66D" "[\\u4E00-\\u9FA5]+|[^\\u4E00-\\u9FA5/ ]+|[\\s]+");;("A" " " "3.2" "测" "," "试" "5.66D")
;;中文(parse3 "A 3.2测,试5.66D" "[\\u4E00-\\u9FA5]+");;("测" "试")
;;英文(parse3 "A 3.2测,试5.66D" "[^\\u4E00-\\u9FA5]+");;("A 3.2" "," "5.66D")
(defun parse3 (str delim)
(xd::string:regexps delim str "")
)
;;85.4 [功能] 字符串分割
;;这是一个很牛的分割法(基本同parse8),容易理解
;;delim是一个字符串集合,其中的每一个字符都会被当作是分割符号 by qjchen@gmail.com
;;如 (parse4 "符号25 35 45 ; 55, 66 " " ;")=> ("25" "35" "45" "55," "66")
;;(parse4 "aa ,10 b.10x20,.2" ",.")("aa " "10 b" "10x20" "2")
(defun parse4 (str delim / L1 L2)
(setq str (vl-string->list str)
delim (vl-string->list delim)
)
(while str
(if (not (member (car str) delim))
(setq l1 (cons (car str) l1))
(if l1
(setq l2 (cons (vl-list->string (reverse l1)) l2)
l1 nil
)
)
)
(setq str (cdr str))
)
(if l1
(setq l2 (cons (vl-list->string (reverse l1)) l2))
)
(reverse l2)
)
;;85.5 [功能] 字符串分割(这highflybird回答我的求助,简洁)
;;(parse5 "aa 10 b10x20.2" "")返回("AA" "10" "B10X20")
;;(parse5 "aa 10 b10x20.2" ".")返回("AA" "10" "B10X20" "2")
(defun parse5 (String Delimiter / str lst)
;;替换成空格,为后面转化作准备,问题是如果字符中原来就有空格
(setq str (VL-STRING-TRANSLATE Delimiter " " String))
(setq str (strcat "(" str ")")) ;加括号
(setq lst (read str)) ;读
(mapcar 'VL-PRINC-TO-STRING lst) ;转化
)
;;85.6 [功能] 用分隔符解释字符串成表 ;by fsxm
;;空格" ",不能用"" ,一个空格就转成一个字符
;;(parse6 "aa 10 b10x20.2" " ")返回("aa" "" "" "10" "b10x20.2")
;;(parse6 "aa 10 b10x20.2" "")死循环
(defun parse6 (string strkey / PO STRLST XLEN)
(setq xlen (1+ (strlen strkey)))
(while (setq po (vl-string-search strkey string))
(setq strlst (cons (substr string 1 po) strlst))
(setq string (substr string (+ po xlen)))
)
(reverse (cons string strlst))
)
;;85.7 [功能] 字符串分割 黄明儒 2013年8月9日
;;改自梁雄啸str2lst1;同parse5,也parse6一样,空格不能有""替代
;;(parse7 "aa 10 b10x20.2" " ");("aa" "" "" "10" "b10x20.2")
;;(parse7 "aa 10 b10x20.2" "")死循环
;;(parse7 "aa 10 b10x20.2" " ")("aa" "10" "b10x20.2")与parse5不同,不会去掉.2
;;(parse7 "aa 10 b10x20.2" "x")("aa 10 b10" "20.2")
(defun parse7 (str delim / I)
(while (setq i (vl-string-search
delim
str
(if i
(+ 2 i)
0
)
)
)
(setq str (vl-string-subst "\"\"" delim str i))
)
(read (strcat "(\"" str "\")"))
)
;;85.8 [功能] 字符串分割(基本同parse4)
;;改自梁雄啸str2lst2 黄明儒 2013年8月9日
;;(parse8 "aa ,10 b.10x20,.2" ",.")("aa " "10 b" "10x20" "" "2")
;;(vl-list->string '(40));"("
;;(vl-list->string '(34)),"\""
;;(vl-list->string '(32))," "
(defun parse8 (str delim / DELIM X)
(setq delim (vl-string->list delim))
(read
(vl-list->string
(apply
'append
(mapcar '(lambda (x)
(if (member x delim)
(list 34 32 34)
(list x)
)
)
(append (list 40 34) (vl-string->list str) (list 34 41))
)
)
)
)
)
;;85.9 [功能] 字符串分割 (纯lisp法)
;;改自梁雄啸str2lst3 黄明儒 2013年8月9日
;;(parse9 "aa 10 b10x20.2" " ");("aa" "" "" "10" "b10x20.2")
;;(parse9 "aa 10 b10x20.2" ""),没作用,但不进入死循环
(defun parse9 (str delim / I S STR1 STRLST)
(setq i 0
str1 ""
)
(while (/= "" (setq s (substr str (setq i (1+ i)) 1)))
(cond ((/= delim s) (setq str1 (strcat str1 s)))
(T
(setq strlst (append strlst (list str1))
str1 ""
)
)
)
)
(if (/= str1 "")
(append strlst (list str1))
strlst
)
)
;;85.10 [功能] 字符串分割(纯lisp法)
;;改自梁雄啸str2lst 黄明儒 2013年8月9日
;;(parse10 "aa 10 b10x20.2" " ");("aa" "" "" "10" "b10x20.2")
;;(parse10 "aa 10 b10x20.2" ""),没作用,但不进入死循环
(defun parse10 (str delim / I S STR1)
(setq i 0
str1 ""
)
(while (/= "" (setq s (substr str (setq i (1+ i)) 1)))
(setq str1 (strcat str1
(if (= delim s)
"\" \""
s
)
)
)
)
(read (strcat "(\"" str1 "\")"))
)
;;85.12 [功能] 字符串分割 By st788796
;;基本同上parse4 parse8
;;(parse12 "aa ,10 b.10x20,.2" ",."),("aa ,10 b.10x20" "2")
;;(parse12 "aa ,10 b.10x20,.2" "")死循环
(defun parse12 (str delimiter / POST STRL STRLST)
(setq strl (strlen delimiter))
(while (vl-string-search delimiter str)
(setq post (vl-string-search delimiter str))
(setq strlst (append strlst (list (substr str 1 post))))
(setq str (substr str (+ post (1+ strl))))
)
(vl-remove "" (append strlst (list str)))
) |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
评分
-
查看全部评分
|