plecs 发表于 2022-7-5 18:35:13

我需要帮助写信。txt fi

我有一个txt文件,我写了之后,我想阅读他的东西,他达到了Ex.side1关键字下面写一行的另两行,因为side3可以做到这一点。
 
有人能帮忙吗
提前谢谢你

Lee Mac 发表于 2022-7-5 18:54:27

我是否正确理解了您希望在文本文件中与给定字符串匹配的行下面插入新行?
 
例如。:
abc
def
side1
ghi
jkl
 
将成为:
abc
def
side1
new text
ghi
jkl

plecs 发表于 2022-7-5 18:59:33

是的,你知道我喜欢什么
当文字到达side1时,我会在下面写一行

plecs 发表于 2022-7-5 19:12:10

我做不到你可以帮我

Lee Mac 发表于 2022-7-5 19:17:16

下面是一个简单的示例:
(defun insertlinebelow ( txt str new / des flg lin lst )
   (if
       (and
         (setq txt (findfile txt))
         (setq des (open txt "r"))
       )
       (progn
         (while (setq lin (read-line des))
               (if (= str lin)
                   (setq lst (vl-list* new lin lst) flg t)
                   (setq lst (cons lin lst))
               )
         )
         (close des)
         (if (and flg (setq des (open txt "w")))
               (progn
                   (foreach str (reverse lst)
                     (write-line str des)
                   )
                   (close des)
                   t
               )
         )
       )
   )
)
 
使用文件名、要匹配的行和新文本调用,例如:
(if (setq fnm (getfiled "" "" "txt" 16))
   (insertlinebelow fnm "side1" "new text")
)
 
如果成功,函数将返回T,如果未找到/无法读取/无法写入输入文件,或者如果在内容中未找到给定行,则返回nil。

plecs 发表于 2022-7-5 19:32:19

谢谢你的帮助

Lee Mac 发表于 2022-7-5 19:44:57

不客气。
页: [1]
查看完整版本: 我需要帮助写信。txt fi