明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3222|回复: 17

[已解答] 字符 1-6 转换成 “1” “2” “3” “4” “5” “6”

[复制链接]
发表于 2014-6-21 18:51:15 | 显示全部楼层 |阅读模式
1-6  转换成 “1” “2” “3” “4” “5” “6”
1-6+8 转换成 “1” “2” “3” “4” “5” “6” ”8“
8+1-6  转换成 “1” “2” “3” “4” “5” “6” ”8“
- 表示 从1 到6的意思
+表示在加一个数
 楼主| 发表于 2014-6-22 08:43:13 | 显示全部楼层
(if (or (wcmatch txt1 "*-*")(wcmatch txt1 "*+*"))(progn
    (if (wcmatch txt1 "*-*")
     (progn
      (setq x1 (substr txt1  (+ 1 (vl-string-position (ascii "-") txt1)))
            x2 (atof(vl-string-subst " " x1 txt1))
            x3 (atof(substr txt1 (+ 2 (vl-string-position (ascii "-") txt1))))
            n2 x2
      )
      (while (<= n2 x3 )
        (setq gna (list (rtos x2 2 0))  oba (append gna oba))
        (setq x2 ( + 1 x2))
        (setq n2 (+ n2 1))
      )
     )
    )
    (if (wcmatch txt1 "*+*")
      (setq x4 (substr txt1  (+ 1 (vl-string-position (ascii "+") txt1)))
            x5 (atof(vl-string-subst " " x4 txt1))
            x6 (atof(substr txt1 (+ 2 (vl-string-position (ascii "+") txt1))))
            gna (list (rtos x6 2 0) (rtos x5 2 0))  oba (append gna oba)   
      )
    )
    (setq obb (del-same oba) lst (vl-sort obb '< ))
    (setq gnb (list (length lst) lst b1)))
 楼主| 发表于 2014-6-22 08:45:00 | 显示全部楼层
这样 好像不行的
发表于 2014-6-22 09:20:26 来自手机 | 显示全部楼层
第一步,读取加减字符串,以加号作为分隔符分解2个字符串 1~6 8
读取分解串,发现减号再分解字符串  1 6并atoi出数字计算生成连续字符
合并连续字符和加号分割字符串
排序完成



发表于 2014-6-22 09:26:20 | 显示全部楼层
可先将字符串用 + 字符分割为1个或多个子字符串
再判断各子字符串中有无 - 字符,对各子字符串进行处理
将子字符串的处理结果合并
供参考
发表于 2014-6-22 09:31:53 | 显示全部楼层
Command: (parse txt1 "-")
("1" "6")
-------------- 部份思路
(setq a (parse txt1 "-")   ; ==> ("1" "6")
      b (mapcar 'atoi a)
      c (car b)
      d (cadr b)
      
)
(while (< c d)
  (setq s (cons c s)
        c (1+ c)
))
(setq s (reverse (cons d s)))
(mapcar 'itoa s)
发表于 2014-6-22 12:27:41 | 显示全部楼层
  1. (defun parse9 (str delim / I S STR1 STRLST)
  2.   (setq        i 0 str1 "")
  3.   (while (/= "" (setq s (substr str (setq i (1+ i)) 1)))
  4.     (cond ((/= delim s) (setq str1 (strcat str1 s)))
  5.           (T (setq strlst (append strlst (list str1)) str1 ""))         
  6.     )
  7.   )
  8.   (if (/= str1 "")
  9.     (append strlst (list str1))
  10.     strlst
  11.   )
  12. )

  13. (defun sk_str->delim(txt / a nlst B C D K)
  14.    (vl-load-com)  
  15.   (if (or (wcmatch txt "*-*")(wcmatch txt "*+*"))
  16.     (progn
  17.       (setq txt(parse9 txt "+") nlst '())
  18.       (while(setq a(car txt))
  19.         (if (wcmatch a "*-*")
  20.           (progn
  21.             (setq b(parse9 a "-"))
  22.             (mapcar 'set '(c d)(list (atoi(car b)) (atoi(cadr b))))
  23.             (setq k (- (min c d) 1))
  24.             (repeat(if(< c d)(1+(- d c))(1+(- c d)))
  25.               (setq nlst(cons (setq k(1+ k)) nlst))             
  26.               )
  27.             )
  28.           (setq nlst(cons (atoi a) nlst))
  29.           )
  30.         (setq txt (cdr txt))
  31.         )
  32.       (setq nlst(vl-sort nlst '<)
  33.             nlst(mapcar 'itoa nlst))
  34.       )
  35.     )
  36.   )
  37. ;;测试程序
  38. (defun c:tt()  
  39. (setq txt "86+0-60")
  40.   (sk_str->delim txt)
  41.   )

评分

参与人数 1金钱 +20 收起 理由
kblh + 20

查看全部评分

发表于 2014-6-22 12:50:38 | 显示全部楼层
  1. ;; (aaa "8+1-6+10-20") → '("8" "1" "2" "3" "4" "5" "6" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20")
  2. (defun aaa (str / lst a b a1 a2)
  3.   (foreach tx (xyp-Get-Str2Lstspr str "+")
  4.     (if  (vl-string-search "-" tx)
  5.       (progn
  6.         (setq b (xyp-Get-Str2Lstspr tx "-")
  7.               a1 (atoi (car b))
  8.               a2 (atoi (cadr b))
  9.         )
  10.         (while (<= a1 a2)
  11.           (setq lst (cons (itoa a1) lst)
  12.                 a1  (1+ a1)
  13.           )
  14.         )
  15.       )
  16.       (setq lst (cons tx lst))
  17.     )
  18.   )
  19.   (reverse lst)
  20. )
 楼主| 发表于 2014-6-22 14:05:03 | 显示全部楼层
no function definition: XYP-GET-STR2LSTSPR
 楼主| 发表于 2014-6-22 14:27:41 | 显示全部楼层
edada  在没有“-” 和 “+”时 不对  
如 1 不能得到 “1”
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 13:36 , Processed in 0.168715 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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