明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 839|回复: 2

[提问] 取字符串里面的数字

[复制链接]
发表于 2019-10-9 13:43:35 | 显示全部楼层 |阅读模式
有一个字符串str  
(setq str "你好Q1000X10X1000.0 天气100 太阳10" )
如何把里面的数字取出来,放到n1,n2,n3,n4,n5  ?


求得 n1="1000"
n2="10"
n3="1000.0"
n4="100"
n5="10"


发表于 2019-10-9 14:23:52 | 显示全部楼层
(getNumberS  "你好Q1000X10X1000.0 天气100 太阳10") =》  (1000 10 1000.0 100 10)

;;自贡黄明儒--提取数字
(defun getNumberS (str / ASC N STR1 STRN)
  (setq n 1)
  (setq str1 "")
  (repeat (strlen str)
    (setq strn (substr str n 1))
    (setq Asc (ascii strn))
    (if        (or (and (> Asc 47) (< Asc 58)) (= Asc 46))
      (setq str1 (strcat str1 strn))
      (setq str1 (strcat str1 " "))
    )
    (setq n (1+ n))
  )
  (strinSplitS str1)
)
(defun strinSplitS (str / lst)
  (setq str (STRCAT "(" str ")"))
  (setq lst (read str))
  (setq lst (mapcar 'VL-PRINC-TO-STRING lst))
)

点评

这个能提取所有数字吗?  发表于 2019-11-21 09:34
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-18 15:45 , Processed in 0.169417 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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