明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1992|回复: 13

[提问] 悬赏20个明经币求高手出手:关于字符串修改类的子函数

[复制链接]
发表于 2017-10-19 12:53 | 显示全部楼层 |阅读模式
20明经币
字符串内容类似于:“墙12架13管144埋122” 转化为:字符串表((“墙” "12")("架 “ ” 13”)("管 “ ” 144”)("埋 “ ” 122”))
悬赏20个明经币求关于字符串转为字符串表的子函数,望高手出手!!!!


最佳答案

查看完整内容

(defun by:DIV( str / a ) (Div_list_by_2 (BY:DivStrByCEN str)) ) (defun Div_list_by_2 (lst / new_lst ) (while lst (setq new_lst (append new_lst (list (list (car lst) (cadr lst)))) lst (cddr lst) ) );end while lst new_lst ) (defun BY:DivStrByCEN (str / &str1;合并后的同类子串 c n1 resultList $oldtype $type ) (setq result ...
发表于 2017-10-19 12:53 | 显示全部楼层
本帖最后由 Gu_xl 于 2017-10-20 10:18 编辑

(defun by:DIV( str / a )
  (Div_list_by_2 (BY:DivStrByCEN str))
  )

(defun Div_list_by_2 (lst / new_lst )
  (while lst
    (setq new_lst (append new_lst (list (list (car lst) (cadr lst))))
          lst (cddr lst)
          )
    );end while lst
  new_lst
  )

(defun BY:DivStrByCEN (str / &str1;合并后的同类子串
                       c n1 resultList  $oldtype $type )
  (setq resultList '())
  (while (/= str "")
    (setq c (substr str 1 1)
          n1 (ascii c)
          )
    ;读取一个字串符,并得到ascii码
    (cond
      ((and (< n1 128)                              ;英文的ascii码都小于128
            (or (< (ascii c) 48) (>  (ascii c) 57));非数字
            )
       (setq $type "英文")
       (if (/= $oldtype $type)
         (progn
           (if &str1 (setq resultList (append resultList (list &str1))))     ;上一种字符串加入表
           (setq &str1 c)
         )
         ;else合并
         (progn
           (setq &str1 (strcat &str1 c))
         )
       );end if
       (setq $oldtype "英文"
             str (substr str 2)                ;字符串前减1
             )
       );end 英文


      ((and (> (ascii c) 47)
            (<  (ascii c) 58))                ;数字
       (setq $type "数字")
       (if (/= $oldtype $type)
         (progn
           (if &str1 (setq resultList (append resultList (list &str1))))     ;上一种字符串加入表
           (setq &str1 c)
         )
         ;else合并
         (progn
           (setq &str1 (strcat &str1 c))
         )
       );end if
       (setq $oldtype "数字"
             str (substr str 2)                ;字符串前减1
             )
       );end 数字


      ((> n1 127)                                      ;中文
       (setq $type "中文")
       (if (/= $oldtype $type)
         (progn
           (if &str1 (setq resultList (append resultList (list &str1))))     ;上一种字符串加入表
           (setq &str1 (substr str 1 2));中文取两位
         )
         ;else合并
         (progn
           (setq &str1 (strcat &str1 (substr str 1 2)));中文取两位
         )
       );end if
       (setq $oldtype "中文"
             str (substr str 3)                ;字符串前减2
             )
       )

      );end cond
    );while
  (setq resultList (append resultList (list &str1)))     ;上一种字符串加入表
  ;返回
  resultList
);end defun
回复

使用道具 举报

发表于 2017-10-19 14:01 来自手机 | 显示全部楼层
本帖最后由 xinxirong 于 2017-10-19 14:38 编辑

手机版显示有问题
回复

使用道具 举报

发表于 2017-10-19 14:56 | 显示全部楼层
把表情改为:即可,提资时自动转换为表情了。
回复

使用道具 举报

发表于 2017-10-19 15:41 | 显示全部楼层
  1. (defun StrType(a / b c d e);;字符串分离全角、符号、字母、数字,已知BUG:连续小数点与数字相连不能精确分离数字和小数点
  2.   (setq b(vl-string->list a))
  3.   (while b
  4.     (setq a(car b)b(cdr b)c(last d))
  5.     (if(or(not d)
  6.           (and(< 0 a 32)(< 0 c 32));;非打印字符
  7.           (or(= 46 a)(= 46 c)(and(< 47 a 58)(< 47 c 58)));数字和小数点
  8.           (vl-every'(lambda(x)(vl-some'(lambda(y)(<(car y)x(cadr y)))'((31 48)(57 65)(90 98)(122 129))))(list a c));其它字符包括小数点
  9.           (vl-every'(lambda(x)(vl-some'(lambda(y)(<(car y)x(cadr y)))'((64 91)(96 123))))(list a c));;字母
  10.           (and(> a 128)(> c 128)));;全角字符
  11.       (if(> a 128)(setq d(vl-list*(car b)a d)b(cdr b))(setq d(cons a d)))
  12.       (setq e(cons(reverse d)e)d(if(> a 128)(list(car b)a)(List a))b(if(> a 128)(cdr b)b))))
  13.   (mapcar'vl-list->string(reverse(cons(reverse d)e))))

;;(StrType"墙12架13管144埋122")->("墙" "12" "架" "13" "管" "144" "埋" "122")
回复

使用道具 举报

 楼主| 发表于 2017-10-19 16:33 | 显示全部楼层
llsheng_73 发表于 2017-10-19 15:41
;;(StrType"墙12架13管144埋122")->("墙" "12" "架" "13" "管" "144" "埋" "122")

谢谢73哥,你这个转换的我有了,我要的是((“墙” "12")("架 “ ” 13”)("管 “ ” 144”)("埋 “ ” 122”)),里面也是表,表里有子表。类型与多维表。
回复

使用道具 举报

 楼主| 发表于 2017-10-19 16:39 | 显示全部楼层
xinxirong 发表于 2017-10-19 12:53
(defun byIV( str / a )
  (Div_list_by_2 (BYivStrByCEN str))
  )

谢谢大神,完美解决!
回复

使用道具 举报

发表于 2017-10-19 17:33 | 显示全部楼层
本帖最后由 llsheng_73 于 2017-10-19 17:38 编辑
水吉空 发表于 2017-10-19 16:33
谢谢73哥,你这个转换的我有了,我要的是((“墙” "12")("架 “ ” 13”)("管 “ ” 144”)("埋 “  ...

(SETQ A(StrType"墙12架13管144埋122"))
("墙" "12" "架" "13" "管" "144" "埋" "122")
_$ (Mapcar'list(vl-remove-if'distof a)(vl-remove-if-not'distof a))
(("墙" "12") ("架" "13") ("管" "144") ("埋" "122"))

(defun divlst(lst n / a b)
    (while lst(setq b nil)
      (repeat(min(length lst)n)(setq b(cons(car lst) b)lst(cdr lst)))
      (setq a(cons b a)))
    (mapcar'reverse(reverse a)))
DIVLST
_$ (divlst(StrType"墙12架13管144埋122")2)
(("墙" "12") ("架" "13") ("管" "144") ("埋" "122"))

回复

使用道具 举报

发表于 2017-10-19 17:36 | 显示全部楼层
本帖最后由 springwillow 于 2017-10-19 17:44 编辑
  1. (defun ccc()
  2.   (setq lst (xxexp "[\\d,\\.]+|[^\\d,\\.]+" "墙12架13管144埋122" ""))
  3.   (mapcar '(lambda(a b)(list a b)) (reverse(cdr(reverse lst)))(cdr lst))
  4.   )

xxexp请在本站搜索一刀屠文正则表达式,可能还有更简单的办法,暂时未想到
回复

使用道具 举报

 楼主| 发表于 2017-10-19 19:39 | 显示全部楼层
llsheng_73 发表于 2017-10-19 17:33
(SETQ A(StrType"墙12架13管144埋122"))
("墙" "12" "架" "13" "管" "144" "埋" "122")
_$ (Mapcar'lis ...

谢谢73哥。。。。。。。。。。。。。。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 08:17 , Processed in 5.987044 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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