Ahmeds 发表于 2022-7-6 07:09:28

获取内部字符串数

如果我有一个名为(例如边界)的层,这个层只有一个内容。
例如:

 
我的问题是,我怎么才能得到放在绳子中间的“45000”或“120000”?

pBe 发表于 2022-7-6 07:15:36

(defun _extract(str)
   (vl-list->string
         (vl-remove-if-not
               '(lambda (x)
                        (or (< 47 x 58)
                            (= x 44)))
               (vl-string->list str))))
 

(defun _extract(str / a b)
   (while (and (setq a (substr str 1 1))
               (not (eq a "")))
         (if (or (< 47 (ascii a) 58)
                   (= (ascii a) 44))
               (setq b   (strcat (if b b "") a)
                     str (substr str 2))
               (setq str (substr str 2))))
   b)

Tharwat 发表于 2022-7-6 07:17:30

另一个

(defun PeelStrings (st / s)
(if (eq (type st) 'STR)
   (foreach x (vl-string->list st)
   (if (member x '(47 48 49 50 51 52 53 54 55 56 57 58 44))
       (setq s (cons x s))
   )
   )
)
(vl-list->string (reverse s))
)

pBe 发表于 2022-7-6 07:21:53

递归
 
(defun _extract (str b / a)
   (setq a (substr str 1 1))
             (if (and(not (eq a "."))
                     (or (numberp (read a))(eq a ",")))
                         (setq b (strcat b a) str (substr str 2))
                       (setq str (substr str 2)))
                   (if (eq str "")
                   b (_extract str b))
   )

Ahmeds 发表于 2022-7-6 07:22:20

至Tharwat或pBE,
 
你能给我一个例子,如何在我的层“边界”中使用这个字符串(“A=45000平方米”)吗?

Tharwat 发表于 2022-7-6 07:26:47

 
例如
 

(peelstrings "A=45,000 SQ.M.")

Ahmeds 发表于 2022-7-6 07:28:56

谢谢塔瓦。

Tharwat 发表于 2022-7-6 07:33:45

 
不客气

Lee Mac 发表于 2022-7-6 07:37:42

如果需要在LISP中使用数值:
 
(defun parse ( s )
   (read
       (vl-list->string
         (apply 'append
               (mapcar
                   (function
                     (lambda ( x ) (if (< 47 x 58) (list x)))
                   )
                   (vl-string->list s)
               )
         )
       )
   )
)

Ahmeds 发表于 2022-7-6 07:39:18

李,我无意冒犯你,因为你的代码和Tharwat的输出几乎与我所需要的相同,但我更喜欢这样:

(peelstrings "A=45,000 SQ.M.")

 
但我还有一个问题要问你们,因为我自己也试过很多次,我就是无法得到确切的代码。
我想得到该层的值(字符串)(例如“boundary”),这样我就不必每次使用“PEELSTRINGS”命令时都写这个(A=45000平方米)。
 
我想要这样:
(setq Bound <code.....>)
(peelstrings "bound")
 
这一个应该得到层“边界”所具有的字符串。
页: [1] 2
查看完整版本: 获取内部字符串数