找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 467|回复: 3

[每日一码] String Split Groups

[复制链接]

已领礼包: 1268个

财富等级: 财源广进

发表于 2018-11-26 20:13:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 st788796 于 2018-11-26 20:37 编辑

Call the function string-split-groups to split a string into a list of strings grouped by ranges of characters found consecutively in the original string. E.g. say you want the alphabetic and numeric characters extracted from a string like "AF023-BZ056" into a list like ("AF" "023" "-" "BZ" "056") for easier manipulations like incrementing.Note: This function uses VisualLisp codes (if existing) which may not be available in your version of CAD. It has only been tested on full AutoCAD 2008-2012 running in Windows XP-32bit & Windows 7 - 64 bit. If your version of CAD does not contain the visual lisp functions required, then a less efficient (AutoLisp-only) method will be used to calculate the groups.
Syntax(string-split-groups <string> <groups>) --> (<grouping1> <grouping2> ... <groupingN>)

Returns a newly created list containing strings grouped by the specified ranges of characters.ArgumentsBoth these arguments are treated as by-value calls. Ensure you don't send quoted symbols as they might be altered inside the function.
<string>Required value of the original string. It can be any of the following:
  • A direct coded string like "Test String".
  • A variable containing a string.
  • The result of a function call as a string value.
<groups>Required list containing wcmatch patterns for each group to split the string into. The pattern must be in a form matching a single character. Any characters found in the string, not matching any of the specified groups will be deemed to be in a default group. It can be any of the following:
  • A direct quoted list like '("@" "#").
  • A variable containing a list.
  • A list created from direct coded strings, string results from a function call and / or variables like (list "[- _]" digits (roman-numerals))
  • The result of a function call as a list of strings containing these groups.
ResultA newly created single dimensional list containing strings extracted from the original string. Each are the consecutive characters matching into a single group.


  1. (defun string-split-groups (string groups / temp char last-group result test-groups found
  2.                            )
  3.   (if (and vl-position)
  4.     (defun test-groups (char /)
  5.       (vl-position
  6.         t
  7.         (mapcar (function (lambda (grp) (wcmatch char grp))) groups)
  8.       )
  9.     )
  10.     (defun test-groups (char / n)
  11.       (setq n 0)
  12.       (while (and (< n (length groups))
  13.                   (not (wcmatch char (nth n groups)))
  14.              )
  15.         (setq n (1+ n))
  16.       )
  17.       (if (< n (length groups))
  18.         n
  19.       )
  20.     )
  21.   )
  22.   (if (> (strlen string) 0)
  23.     (setq last-group (test-groups (setq char (substr string 1 1)))
  24.           temp       char
  25.           string     (substr string 2)
  26.     )
  27.   )
  28.   (while (> (strlen string) 0)
  29.     (if (/= last-group
  30.             (setq found (test-groups (setq char (substr string 1 1))))
  31.         )
  32.       (setq result     (cons temp result)
  33.             temp       ""
  34.             last-group found
  35.       )
  36.     )
  37.     (setq temp   (strcat temp char)
  38.           string (substr string 2)
  39.     )
  40.   )
  41.   (reverse (cons temp result))
  42. )

ExamplesGroup all alphabetic and numerals separate from other characters.
(string-split-groups " B01 - B02" '("@" "#")) ; --> (" " "B" "01" " - " "B" "02")


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 6881个

财富等级: 富甲天下

发表于 2018-11-26 21:38:47 | 显示全部楼层
是不是
字符串分割为表
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 19个

财富等级: 恭喜发财

发表于 2018-11-26 21:54:53 | 显示全部楼层
英文看着实在是晕,用谷歌翻译下

===============================================

调用函数string-split-groups将字符串拆分为按原始字符串中连续找到的字符范围分组的字符串列表。例如。假设您希望将字母和数字字符从“AF023-BZ056”这样的字符串中提取到类似(“AF”“023”“ - ”“BZ”“056”)的列表中,以便更轻松地进行操作。注意:此函数使用VisualLisp代码(如果存在)可能在您的CAD版本中不可用。它仅在运行Windows XP-32bit和Windows 7 - 64位的完整AutoCAD 2008-2012上进行了测试。如果您的CAD版本不包含所需的可视化lisp函数,则将使用效率较低(仅限AutoLisp)的方法来计算组。
语法(string-split-groups <string> <groups>) - >(<grouping1> <grouping2> ... <groupingN>)

返回一个新创建的列表,其中包含按指定的字符范围分组的字符串.Arguments这些参数被视为按值调用。确保您不发送带引号的符号,因为它们可能在函数内部被更改。
<string>原始字符串的必需值。它可以是以下任何一种:
直接编码的字符串,如“Test String”。
包含字符串的变量。
函数调用的结果为字符串值。
<groups>包含要将字符串拆分为的每个组的wcmatch模式的必需列表。模式必须采用与单个字符匹配的形式。在字符串中找到的任何字符都不会与任何指定的组匹配,将被视为默认组。它可以是以下任何一种:
直接引用的列表,如'(“@”“#”)。
包含列表的变量。
从直接编码字符串创建的列表,来自函数调用的字符串和/或类似的变量(列出“[ - _]”数字(罗马数字))
函数调用的结果作为包含这些组的字符串列表。
ResultA一个新创建的单维列表,包含从原始字符串中提取的字符串。每个都是匹配到单个组中的连续字符。

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 6468个

财富等级: 富甲天下

发表于 2018-11-27 00:08:29 | 显示全部楼层
翻译成中文就好理解多了。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-17 02:25 , Processed in 0.315952 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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