明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[求助]如何提取比如“"P1-60"”中的60和“P1-”

  [复制链接]
发表于 2009-8-29 21:36:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-8-29 22:09:00 | 显示全部楼层
正则表达式求
发表于 2009-8-30 11:12:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-8-30 15:09:00 | 显示全部楼层
刚注册就碰到这个问题,呵呵
最近刚刚为了给标号添加编号而写的,标注数据炸散函数
可以将如 15T32-6,7-250 D.S. 这样的箍筋标注文字分解成 15,"T","6,7",250,"D.S." 然后做成关联表返回

;;; SPL_BE:XP_STPLBL = 分析箍筋标注文本

;;;    Note:
;;;        in     箍筋标注的 e-list
;;;        do    将字符串中的
;;;                对象定义数据        >> (el_elst     <e-list>)
;;;                箍筋根数        >> (i_a     .     a)    ! 还没有箍筋根数时,a 的值保存为 0
;;;                T/Y            >> (str_b     .     b)
;;;                箍筋直径         >> (i_c     .     c)
;;;                箍筋编号前面的'_'    >> (pos_d1     .     d1)
;;;                箍筋编号        >> (str_d     .     d)    ! 还没有箍筋编号时,d 的值保存为 "" 空字符串
;;;                箍筋间距前面的'_'    >> (pos_d1     .     d1)
;;;                箍筋间距        >> (i_e     .     e)
;;;                箍筋肢数        >> (str_f     .     f)
;;;            分析出来,放入关联表中        >> (    (str_f . f)
;;;                                (i_e . e)
;;;                                (str_d . d)
;;;                                (i_c . c)
;;;                                (i_a . a)
;;;                                (str_b . b)
;;;                                (pos_e1 . e1)
;;;                                (pos_d1 . d1)
;;;                                (el_elst     <对象定义数据>)
;;;                               )
;;;        return    返回以上分析所得的关联表,供后续使用


(defun SPL_BE:XP_STPLBL    (
             xpstplbl:elStpLbl
             /
             xpstplbl:strStpLbl
             xpstplbl:lstReturn
             xpstplbl:strStpLbl_b
             xpstplbl:posStpLbl_b
             xpstplbl:posStpLbl_d1
             xpstplbl:posStpLbl_e1
            )
    (setq
    xpstplbl:strStpLbl                                        ; STEP.1 >> 从 e-list 中提取文本信息
       (vl-string-trim ;_必要的处理,移除前导和后导的空格和“-”连字符
           " -"
           (cdr (assoc 1 xpstplbl:elStpLbl))
       )


    xpstplbl:lstReturn                                        ; STEP.2 >> 将 e-list 保存进结果关联表
       (cons (cons 'el_elst
               xpstplbl:elStpLbl
         )                                            ;     构造点对表 >> (el_elst . elst)
         nil
       )                                                ;     初始化结果关联表 << ((el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.3 >> 提取第一个 "-" 的位置号 (posstion = displacement + 1)
       (cons (cons 'pos_d1
               (setq xpstplbl:posStpLbl_d1
                (1+ (vl-string-position
                    (ascii "-")
                    xpstplbl:strStpLbl
                    )
                )
               )

         )                                            ;     构造点对表 >> (pos_d1 . d1)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.4 >> 提取第二个 "-" 的位置号 (posstion = displacement + 1)
       (cons (cons 'pos_e1
               (setq xpstplbl:posStpLbl_e1
                (1+ (vl-string-position
                    (ascii "-")
                    xpstplbl:strStpLbl
                    nil
                    t
                    )
                )
               )

         )                                            ;     构造点对表 >> (pos_e1 . e1)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.5 >> 提取 b 值 << 箍筋标注用 T 还是 Y 筋
       (cons (cons 'str_b
               (setq xpstplbl:strStpLbl_b
                (cond
                    ((wcmatch xpstplbl:strStpLbl "*[Yy]##*")
                     "Y"
                    )
                    (t "T")
                )

               )
         )                                            ;     构造点对表 >> (str_b . b)
         xpstplbl:lstReturn
       )                                                ;      更新结果关联表 << ((str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:posStpLbl_b                                        ; STEP.6 >> 保存标注 T/Y 的位置号,以供后提取 a,c 的值时使用
       (1+ (vl-string-position
           (ascii xpstplbl:strStpLbl_b)
           xpstplbl:strStpLbl
           )
       )

    xpstplbl:lstReturn                                        ; STEP.7 >> 提取 a 的值 << 箍筋根数,如果没有则为 0
       (cons (cons 'i_a
               (cond
               ((wcmatch xpstplbl:strStpLbl "[TYty]*") 0)
               (t
                (atoi
                (substr    xpstplbl:strStpLbl
                    1
                    (- xpstplbl:posStpLbl_b
                       1
                    )
                )
                )
               )
               )
         )                                            ;     构造点对表 >> (i_a . a)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((i_a . a) (str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.8 >> 提取 c 的值 << 箍筋直径
       (cons (cons 'i_c
               (atoi
               (substr xpstplbl:strStpLbl
                   (1+ xpstplbl:posStpLbl_b)
                   2
               )
               )
         )                                            ;     构造点对表 >> (i_c . c)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((i_c . c) (i_a . a) (str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.9 >> 提取 d 的值 << 箍筋编号,如果没有则为空字符串 "" ,不包括前面的 "-"
       (cons (cons 'str_d
               (cond
               ((= xpstplbl:posStpLbl_d1 xpstplbl:posStpLbl_e1) "")
               ;; ((= (- xpstplbl:posStpLbl_e1 xpstplbl:posStpLbl_d1) 1) "")
               ;; 此逻辑不需要,如果两个'-'紧邻,则长度参数为 0,substr 自然返回 ""
               (t
                (substr xpstplbl:strStpLbl
                    (1+ xpstplbl:posStpLbl_d1)
                    (- (- xpstplbl:posStpLbl_e1 xpstplbl:posStpLbl_d1) 1)
                )
               )
               )
         )                                            ;     构造点对表 >> (str_d . d)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((str_d . d)(i_c . c) (i_a . a) (str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.10 >> 提取 e 的值 << 箍筋间距,不包括前面的 "-"
       (cons (cons 'i_e
               (atoi (substr xpstplbl:strStpLbl
                     (1+ xpstplbl:posStpLbl_e1)
                     3
                 )
               )
         )                                            ;     构造点对表 >> (i_e . e)
         xpstplbl:lstReturn
       )                                                ;     更新结果关联表 << ((i_e . e) (str_d . d) (i_c . c) (i_a . a) (str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))

    xpstplbl:lstReturn                                        ; STEP.11 >> 提取 f 的值 << 箍筋肢数,不包括前面的空格
       (cons (cons 'str_f
               (substr xpstplbl:strStpLbl
                   (+ xpstplbl:posStpLbl_e1 5)
                                                    ;     箍筋标注中空格的位置不用计算,可以从 e1 的位置推算出来 = e1 + 4
               )
         )                                            ;     构造点对表 >> (str_f . f)
         xpstplbl:lstReturn
       )                                                ;      更新结果关联表 << ((str_f . f) (i_e . e) (str_d . d) (i_c . c) (i_a . a) (str_b . b) (pos_e1 . e1) (pos_d1 . d1) (el_elst . elst))
    ) ;_ setq 调用结束
)
发表于 2009-8-30 23:22:00 | 显示全部楼层
回9楼:我的函数是为我在程序中的特定功能写的,满足我需要的功能即可,拿出来分享,只是作为一个参考。你提的问题很没有水平,后面的“-”既可理解为负号,也可理解为连接符号,如果你懂编程,我想要稍微修改一下程序即可实现,当然前提你要懂编程序。
发表于 2009-8-31 00:41:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-1 12:28 , Processed in 0.170659 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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