乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 33|回复: 9

[编程交流] 从字符串中删除某些内容

[复制链接]

36

主题

161

帖子

125

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
182
发表于 2022-7-5 16:34:26 | 显示全部楼层 |阅读模式
从字符串中删除[######.##.#
 
如。
“[2017.03.06][2016.12.10]蓝图.dwg”
 
移除时
 
“蓝图.dwg”
回复

使用道具 举报

5

主题

956

帖子

963

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 16:46:18 | 显示全部楼层
 
通常我们会使用wcmatch,
或者,我使用列表方法bcos,因为我看到了括号[##]
 
  1. (setq str "[2017.03.06][2016.12.10]blueprint.dwg")
  2. (strcat        (vl-string-right-trim
  3.   " "
  4.   (apply 'strcat
  5.          (mapcar ''((x) (strcat (vl-princ-to-string x) " "))
  6.                  (vl-remove-if 'vl-consp (read (strcat "(" (vl-string-translate "[]" "()" str) ")")))
  7.                  )
  8.          )
  9.   )
  10. ".dwg"
  11. )
回复

使用道具 举报

36

主题

161

帖子

125

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
182
发表于 2022-7-5 16:54:13 | 显示全部楼层
 
韩,你好,
非常感谢!
我想看看使用wcmatch方法。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:00:25 | 显示全部楼层
使用wcmatch:
  1. ; _$ (foo "[2017.03.06][2016.12.10]Blueprint.dwg") -> "Blueprint.dwg"
  2. ; _$ (foo "[2017.03.06][2016.12.10]This is a test.dwg") -> "This is a test.dwg"
  3. (defun foo ( s )
  4. (cond
  5.    ( (wcmatch s  "`[####`.##`.##`]`[####`.##`.##`]*`.dwg")
  6.      (substr s 25)
  7.    )
  8. )
  9. )
回复

使用道具 举报

36

主题

161

帖子

125

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
182
发表于 2022-7-5 17:01:31 | 显示全部楼层
 
对不起,[#######.##可能不是两个,可能是一个或三个。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:10:14 | 显示全部楼层
另一个,使用正则表达式:
  1. (defun foo ( str / rgx )
  2.    (if (setq rgx (vlax-get-or-create-object "vbscript.regexp"))
  3.        (progn
  4.            (vlax-put-property rgx 'global actrue)
  5.            (vlax-put-property rgx 'pattern "\\[\\d{4}\\.\\d{2}\\.\\d{2}\\]")
  6.            (setq str (vlax-invoke rgx 'replace str ""))
  7.            (vlax-release-object rgx)
  8.            str
  9.        )
  10.    )
  11. )
  1. _$ (foo "[2017.03.06]Blueprint.dwg")
  2. "Blueprint.dwg"
  3. _$ (foo "[2017.03.06][2016.12.10]Blueprint.dwg")
  4. "Blueprint.dwg"
  5. _$ (foo "[2017.03.06][2016.12.10][2016.12.10]Blueprint.dwg")
  6. "Blueprint.dwg"
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:15:21 | 显示全部楼层
 
啊,现在我明白了任务!在这里:
  1. ; _$ (foo "[2013.12.10]Blueprint.dwg") -> "Blueprint.dwg"
  2. ; _$ (foo "[2015.08.10][2016.12.10]This is a test.dwg") -> "This is a test.dwg"
  3. ; _$ (foo "[2012.02.13][1991.08.10][2016.12.10]And Another test.dwg") -> "And Another test.dwg"
  4. (defun foo ( s )
  5. (cond
  6.    ( (wcmatch s  "`[####`.##`.##`]*`.dwg")
  7.      (while (wcmatch s  "`[####`.##`.##`]*`.dwg")
  8.        (setq s (substr s 13))
  9.      )
  10.    )
  11. )
  12. )

 
李,你的密码让我神魂颠倒!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:22:56 | 显示全部楼层
谢谢Grrr
 
请注意,您的代码可能会变成:
这样,如果找不到模式,函数将返回原始字符串,而不是nil。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 17:34:19 | 显示全部楼层
 
谢谢李,有时候我想得太多了,很难看出它可以缩短。
回复

使用道具 举报

36

主题

161

帖子

125

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
182
发表于 2022-7-5 17:37:30 | 显示全部楼层
李,韩,Grrr,非常感谢!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 15:45 , Processed in 1.015064 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表