找回密码
 加入
搜索
查看: 3313|回复: 4

[AU3基础] 文本处理大全

[复制链接]
发表于 2014-3-3 15:09:02 | 显示全部楼层 |阅读模式
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   ;==>
发表于 2014-3-3 16:23:24 | 显示全部楼层
顶楼主,希望再多总结一些文本处理的函数出来。
发表于 2014-3-3 17:53:13 | 显示全部楼层
文本处理是正则的强项
发表于 2014-3-5 09:33:46 | 显示全部楼层
这东西还是需要的时候动动脑好点;什么都要现成的;就没有意思了。但还是感谢楼主提供思路;这个比源码来得重要。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-6 10:21 , Processed in 0.089939 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表