找回密码
 加入
搜索
楼主: gljlmz

[AU3基础] 如何读取TXT文本文档里面指定的字符前面的值或后面的值【已解决】

 火.. [复制链接]
发表于 2012-12-1 22:48:24 | 显示全部楼层
本帖最后由 afan 于 2012-12-1 22:50 编辑
Local $sFile = FileRead('test.txt'), $sDelimiter = '*'
Local $aLineAB = StringRegExp($sFile, '(?m)(.*?)\' & $sDelimiter & '(\V+)', 3)
If @error Then Exit MsgBox(0, '错误', '不能打开文件或文件无指定分割符')
Local $iTotal = UBound($aLineAB), $iStart = 0

HotKeySet('{esc}', '_Exit')        ;按Esc键退出
HotKeySet('{f1}', '_GetData')        ;按一次F1键读一次

While 1
        Sleep(10000)
WEnd

Func _GetData()
        MsgBox(0, ' 行 ' & ($iStart + 2) / 2, $aLineAB[$iStart] & @LF & $aLineAB[$iStart + 1])
        $iStart += 2
        If $iStart = $iTotal Then $iStart = 0
EndFunc   ;==>_GetData
Func _Exit()
        Exit
EndFunc   ;==>_Exit
发表于 2012-12-2 11:26:09 | 显示全部楼层
正则表达式吧 。 \d+
发表于 2012-12-3 20:25:46 | 显示全部楼层
一行里有两个*号怎么办
发表于 2012-12-3 20:44:54 | 显示全部楼层
本帖最后由 netegg 于 2012-12-3 20:48 编辑

[au3]#include <file.au3>
#include  <array.au3>
_filewritetoline('1.txt', 1, '[item]')
_ReplaceStringInFile('1.txt', '*', '=')
$aIni = IniReadSection('1.txt', 'item')
_ArrayDisplay($aIni)[/au3]
来个看着行数少点的
发表于 2012-12-4 18:32:42 | 显示全部楼层
搞得别人机子死循环啊。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-19 00:42 , Processed in 0.068781 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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