明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2367|回复: 1

如何选择单行文本、多行文本中的数字?

[复制链接]
发表于 2005-2-3 17:33:00 | 显示全部楼层 |阅读模式
用(setq ss (ssget '((0 . "TEXT,MTEXT")) ))可以选择单行文本、多行文本。如果只想选择单行文本、多行文本中的数字而把字母、汉字过滤掉,请问应该如何做?
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2005-2-3 19:26:00 | 显示全部楼层
  1.    ; By Bill Kramer
  2. (defun String_To_Numbers (
  3.          inStr   ;;Input string
  4.          /
  5.          Res       ;;Result list
  6.          Buf       ;;String buffer
  7.          Inx           ;;Character location
  8.          CH         ;;Character
  9.          )
  10.    (setq Inx 1 ;start at the beginning of the string
  11.   Buf "" ;init buffer to empty
  12.   )
  13.    ;
  14.    ; Loop until the end of the string.
  15.    ; (I indicates where we are in the string)
  16.    ;
  17.    (while (<= Inx (strlen inStr))
  18.        ;
  19.        ; Get the character at position Inx, increment position indicator
  20.        (setq CH (substr inStr Inx 1)
  21.      Inx (1+ Inx)
  22.      )
  23.        ;
  24.        (cond
  25.            ; Test to see if character is a digit.
  26.            ((wcmatch CH "[0-9.]")
  27.                (if (= CH ".") ;is it decimal?
  28.      (if (not (wcmatch Buf "*`.*")) ;not already in there
  29.          (setq Buf (strcat Buf CH))
  30.          (Flush_Buf))
  31.      ;
  32.                    (setq Buf (strcat Buf CH)))
  33.            )
  34.            ((= Buf "") ;is the buffer empty?
  35.                ;Is CH minus
  36.   (if (= CH "-")
  37.      (setq Buf CH) ;Yes, save in Buf
  38.   )
  39.            )
  40.            ('T ;else buffer is not empty
  41.                (Flush_Buf)
  42.                (if (= CH "-")
  43.      (setq Buf CH))
  44.            )
  45.        ); End of COND
  46.    ); End of WHILE
  47.    ;
  48.    (if (and (/= Buf "")
  49.        (not (wcmatch Buf "[+-.]"))
  50.        )
  51.        (Flush_Buf))
  52.    (reverse Res)
  53. )
  54. ;
  55. ; ------------------------------------------------------ Listing 4.5
  56. ;
  57. (defun Flush_Buf ()
  58.    (if (not (wcmatch Buf "[+-.]")) ;is it not just +-.?
  59.        (progn
  60.            ;Clean it up first
  61.            (if (= (substr Buf 1 1) ".")
  62.   (setq Buf (strcat "0" Buf))) ;;add zero to front if .#
  63.            (if (= (substr Buf (strlen Buf)) ".")
  64.   (setq Buf (substr Buf 1 (1- (strlen Buf))))) ;;remove decimal if #.
  65.            ;Add to RES list
  66.            (setq RES (cons Buf RES))))
  67.    (setq Buf "") ;;reset Buf
  68. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-29 18:20 , Processed in 0.172252 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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