如何在某文本文档(共60行)里的第5行的下一行追加新的文本
Posted: 01 May 2015, 04:01
如题 : 我要在某文本文档中间追加新的文本。
谢谢···········!
谢谢···········!
Let's help each other out
https://www.autohotkey.com/boards/
Code: Select all
AppendText("某文本文档.txt", 5, "新的文本")
AppendText(FileName, LineNum, Text) {
f := FileOpen(FileName, "r")
content_ := ""
Loop, % LineNum
content_ .= f.ReadLine()
newContent := content_ . Text . "`r`n" f.Read()
encoding := f.Encoding
f.Close()
FileOpen(FileName, "w", encoding).Write(newContent)
}
Code: Select all
AppendText(FileName, LineNum, Text) {
f := FileOpen(FileName, "r")
dat := f.Read()
encoding := f.Encoding
f.Close()
dat := RegExReplace(dat, "^(.*?(\R)){" . LineNum . "}", "$0" . Text . "$2")
FileOpen(FileName, "w", encoding).Write(dat)
}