|
Hi,大家好。
平时的时候要文本处理,马上写又会比较麻烦。
有没有人一起写一个文本处理的小工具。
希望大家多多补充,在做个GUI界面
比如把一个文本的每一行倒转一下,最后一行变第一行。。。。
Func _reverse($path)
$text = ""
$readfile = FileOpen($path, 0)
If $readfile = -1 Then Return -1
$i = _FileCountLines($path)
While($i >0)
$text = $text & FileReadLine($readfile,$i) & @CRLF
$i = $i -1
WEnd
FileClose($readfile)
$writefile = FileOpen($path, 2)
FileWriteLine($writefile, $text)
FileClose($writefile)
MsgBox(0,"","Finish !")
EndFunc
批量替换一个文本中的内容
Func _replace($path,$search,$replace)
$text = ""
$readfile = FileOpen($path, 0)
If $readfile = -1 Then Return -1
While 1
$text = $text & FileReadLine($readfile) & @CRLF
If @error = -1 Then ExitLoop
WEnd
FileClose($readfile)
$text = StringReplace ( $text, $search,$replace )
$writefile = FileOpen($path, 2)
FileWriteLine($writefile, $text)
FileClose($writefile)
MsgBox(0,"","Finish !")
EndFunc
给每一行的头尾分别加上一串字符串
Func _addHeadAndTail($path,$head,$tail)
$text = ""
$readfile = FileOpen($path, 0)
If $readfile = -1 Then Return -1
While 1
If @error = -1 Then ExitLoop
$text = $text & $head & FileReadLine($readfile)& $tail & @CRLF
WEnd
FileClose($readfile)
$writefile = FileOpen($path, 2)
If $writefile = -1 Then Return -1
FileWriteLine($writefile, $text)
_FileWriteToLine($path, _FileCountLines($path), "", 1)
FileClose($writefile)
MsgBox(0,"","Finish !")
EndFunc ;==> |
|