乐筑天下

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

[编程交流] addslashes (sort of)

[复制链接]

37

主题

125

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
190
发表于 2022-7-6 10:42:30 | 显示全部楼层 |阅读模式
Sort of addslashes type method; nothing special figured it may be useful at some point to someone.
 
EDIT:
 
Yeah that was a bit off; amended code below
  1. ;;-Ollie;;  Precede each instance of an identifying char (single|group) within the source;  string with a char (single|group);;  text       = (String) source string;  iinsert    = (String) text to insert in front of matches;  identifier = (String) text to be preceded by the insert text in the source string(defun addMidText(text insert identifier / i ids textLen idLen insertionLen) (setq i  0) (setq textLen (strlen text)) (setq idLen(strlen identifier)) (setq insertLen (strlen insert)) (while(< (setq i (1+ i))(- textLen idLen))   (if(eq (substr text i idLen) identifier)     (progn       (setq text     (strcat       (substr text 1 (1- i))       insert       (substr text i (- textLen (1- i)))))   (setq i (+ i  insertLen) textLen(+ textLen insertLen ))     )   )  ) text)
Cheers,
Ollie.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:45:23 | 显示全部楼层
On first testing, I couldn't get it to function, but I may have used it incorrectly,
 
However, what about vl-string-subst?
 
Or for multiple instances:
 
  1. (defun StringSubst ( new old str ) ;; © Lee Mac 2010 (   (lambda ( i / nl ) (setq nl (strlen new))     (while       (and (< i (strlen str))         (setq i (vl-string-search old str i))         (setq str (vl-string-subst new old str i) i (+ i nl))       )     )     str   )   0 ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 17:12 , Processed in 0.603871 second(s), 56 queries .

© 2020-2025 乐筑天下

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