明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2540|回复: 12

[已解答] 求助:字符串分割

[复制链接]
发表于 2014-9-27 20:26:24 | 显示全部楼层 |阅读模式
请问大侠:“ED4-01#100+100 TB 325”怎样以“#”为界分解成“ED4-01”和“100+100 TB 325”两行文字呢

点评

http://bbs.mjtd.com/thread-107150-1-1.html  发表于 2014-9-28 09:06
发表于 2014-9-27 20:41:48 | 显示全部楼层
(setq str "ED4-01#100+100 TB 325")
(parse str "#")

Parse 自定义函数 明经旧帖中有
 楼主| 发表于 2014-9-27 21:26:28 | 显示全部楼层
Andyhon 发表于 2014-9-27 20:41
(setq str "ED4-01#100+100 TB 325")
(parse str "#")

可是我不会把分解成的两行文字插入到原来文字的地方,老大教下我呀
发表于 2014-9-27 22:22:47 | 显示全部楼层
一个最笨的办法:
(defun c:test()
  (vl-load-com)
  (setq zf "ED4-01#100+100 TB 325")
  (setq zf (vl-string-translate "#" " " zf))
  (setq zf (vl-string-translate "+" " " zf))
  (setq zf (read(strcat "(" zf ")")))
  (setq zff1 (car zf))
  (setq zf2 (cadr zf))
  (setq zf3 (caddr zf))
  (setq zf4 (cadddr zf))
  (setq zf4 (vl-string-translate "" "" zf4))
  (setq zf5 (last zf))
  (setq zff2 (strcat (rtos zf2 2 0) "+" (rtos zf3 2 0) " " zf4 " " (rtos zf5 2 0)))
  (print "zff1=")(princ zff1)(princ)
  (print "zff2=")(princ zff2)(princ)
)  

发表于 2014-9-28 00:42:09 | 显示全部楼层
(setq str "ED4-01#100+100 TB 325")
(setq a# (vl-string-search "#" str))
(setq a1 (substr str 1 a#))
(setq a2 (substr str (+ a# 2)))
发表于 2014-9-28 07:29:33 | 显示全部楼层
(defun c:test()
  (vl-load-com)
  (setq zf "ED4-01#100+100 TB 325")
  (setq  m (vl-string-position (ascii "#") zf))
  (setq zf1 (substr zf 1 m) zf2 (substr zf (+ m 2)))
  (print "zf1=")(princ zf1)(princ)
  (print "zf2=")(princ zf2)(princ)
)  
 楼主| 发表于 2014-9-28 11:08:58 | 显示全部楼层
谢谢各位的热心回复,我先在用parse 可以把支付串分解成两个了,但是我不会再原文字位置上写出这两个新文字
发表于 2014-9-28 11:12:39 | 显示全部楼层
小师傅 发表于 2014-9-27 21:26
可是我不会把分解成的两行文字插入到原来文字的地方,老大教下我呀

简单的可以这样
1 先用textbox计算出第一部分"ED4-01"的长度。
2 拷贝原文字,后移一个距离,将内容改为后面的"100+100 TB 325""
 楼主| 发表于 2014-9-28 11:15:20 | 显示全部楼层
自贡黄明儒 发表于 2014-9-28 11:12
简单的可以这样
1 先用textbox计算出第一部分"ED4-01"的长度。
2 拷贝原文字,后移一个距离,将内容改为 ...

谢谢黄大师,我马上试试
发表于 2014-9-28 12:34:51 | 显示全部楼层
小师傅 发表于 2014-9-28 11:15
谢谢黄大师,我马上试试


看看是不是这个意思:
  1. (defun c:ttrim (/ ss i l0 en ne eg ng e0 e1 j sr)
  2.   (command ".color" (getvar "cecolor"))
  3.   (if (not acet-tjust)
  4.     (load "acetutil3")
  5.   )
  6.   (setq sr (getstring "\n输入分隔字符: "))
  7.   (if (member sr '("*" "#" "@" "." "?" "~"))
  8.     (setq sr1 (strcat "`" sr))
  9.     (setq sr1 sr)
  10.   )
  11.   (princ "\n选择需要去分隔符的文本: ")
  12.   (setq ss (ssget (list '(0 . "TEXT") (cons 1 (strcat "*" sr1 "*")))))
  13.   (if ss
  14.     (progn
  15.       (setq l0 (sslength ss)
  16.             i  -1
  17.       )
  18.       (acet-tjust ss "R")
  19.     )
  20.   )
  21.   (repeat l0
  22.     (setq i  (1+ i)
  23.           en (ssname ss i)
  24.           eg (entget en)
  25.           e1 (cdr (assoc 1 eg))
  26.     )
  27.     (if (wcmatch e1 (strcat sr1 "*"))
  28.       (progn
  29.         (setq e1 (vl-string-left-trim sr e1)
  30.               eg (subst (cons 1 e1) (assoc 1 eg) eg)
  31.         )
  32.         (entmod eg)
  33.       )
  34.     )
  35.     (if (wcmatch e1 (strcat "*" sr1))
  36.       (progn
  37.         (acet-tjust (ssadd en) "S")
  38.         (setq eg (entget en)
  39.               e1 (cdr (assoc 1 eg))
  40.               e1 (vl-string-right-trim sr e1)
  41.               eg (subst (cons 1 e1) (assoc 1 eg) eg)
  42.         )
  43.         (entmod eg)
  44.       )
  45.       (acet-tjust (ssadd en) "S")
  46.     )
  47.     (while (wcmatch e1 (strcat "*" sr1 "*"))
  48.       (setq eg (entget en)
  49.             ng (entmake eg)
  50.             ne (entlast)
  51.             ng (entget ne)
  52.             e0 (cdr (assoc 1 ng))
  53.             e0 (substr e0 1 (setq j (vl-string-search sr e0)))
  54.             ng (subst (cons 1 e0) (assoc 1 ng) ng)
  55.       )
  56.       (entmod ng)
  57.       (acet-tjust (ssadd en) "R")
  58.       (setq eg (entget en)
  59.             e1 (cdr (assoc 1 eg))
  60.             e1 (vl-string-left-trim sr (substr e1 (+ j 1)))
  61.             eg (subst (cons 1 e1) (assoc 1 eg) eg)
  62.       )
  63.       (entmod eg)
  64.       (setq eg (entget en)
  65.             e1 (cdr (assoc 1 eg))
  66.       )
  67.       (acet-tjust (ssadd en) "S")
  68.     )
  69.   )
  70.   (princ)
  71. )

这是以前一个小程序改的,需要ET支持。
原帖:http://bbs.mjtd.com/thread-99236-1-1.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 02:07 , Processed in 0.168731 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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