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

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

 火.. [复制链接]
 楼主| 发表于 2012-12-1 21:40:17 | 显示全部楼层
我还没着手写呢就卡在这个循环读取的问题上
 楼主| 发表于 2012-12-1 21:43:45 | 显示全部楼层
谢谢提醒那行号的循环呢
发表于 2012-12-1 21:47:31 | 显示全部楼层
本帖最后由 annybaby 于 2012-12-1 21:56 编辑

回复 16# gljlmz

如果已经知道文件行数可用外while 死循环,内for 循环
如果不知道,可用_fileopen通过@error来判断,然后filesetpos设置到文件开头,外层同样用死循环
字符串分割前面已经说了~~
发表于 2012-12-1 21:51:25 | 显示全部楼层
本帖最后由 netegg 于 2012-12-1 22:01 编辑

local $i=1
while 1
$line = filereadline($file, $i)
if not (@error or $line = '') then
  $a
  $b
else
   $i = 0
endif
$i +=1
wend

记住这是你自己的要求,退不出来自己想办法
 楼主| 发表于 2012-12-1 21:58:29 | 显示全部楼层
Local $i = 0
While $i <= 10
          $i = $i + 1
WEnd
$card=FileReadLine("ID.TXT",$i)
IniWrite("test.ini","I","2",$i)
但是这个$i必须要有一个最大值,可我又不能固定这个TXT里面存多少行
发表于 2012-12-1 22:06:29 | 显示全部楼层
回复 18# annybaby
这个没必要了,单层循环够了
发表于 2012-12-1 22:06:38 | 显示全部楼层
回复 20# gljlmz


楼主你用事实证明了基础知识的重要性~~~

多F1几下吧,磨刀不误砍柴功
发表于 2012-12-1 22:07:52 | 显示全部楼层
本帖最后由 afan 于 2012-12-1 22:15 编辑
Local $file = FileOpen('test.txt', 0), $sDelimiter = '*'
If $file = -1 Then Exit MsgBox(0, '错误', '不能打开文件.')
HotKeySet('{esc}', '_Exit')

Local $line, $location, $iL = 0, $sA = '', $sB = ''
While 1
        $iL += 1
        $line = FileReadLine($file, $iL)
        If @error = -1 Then $iL = 0
        $location = StringInStr($line, $sDelimiter)
        If Not $location Then ContinueLoop
        $sA = StringMid($line, 1, $location - 1)
        $sB = StringMid($line, $location + 1)
        MsgBox(0, '以 "' & $sDelimiter & '" 分割行 ' & $iL, $sA & @LF & $sB)
WEnd

Func _Exit()
        Exit FileClose($file)
EndFunc   ;==>_Exit
发表于 2012-12-1 22:09:09 | 显示全部楼层
现在就是没搞明白,lz所谓的循环读取到底是什么意思,一直不退吗?这种处理文件的方法还从没见过,处理到文件尾又要从头开始处理?
发表于 2012-12-1 22:09:44 | 显示全部楼层
回复 19# netegg

蛋兄,只有你我这样在养膘的人才会回复楼主这样扯蛋的帖子,呵呵~~
发表于 2012-12-1 22:15:32 | 显示全部楼层
回复 25# annybaby
afan也疼着呢,雨天打孩子呗,闲着也是闲着
发表于 2012-12-1 22:16:26 | 显示全部楼层
回复 24# netegg

所以才用两层循环~~
比如

$file=FileOpen('E:\桌面\新建 文本文档.txt')
While 1
        While 1
                $content=FileReadLine($file)
                If @error Then ExitLoop
                ConsoleWrite(@CRLF&$content&@CRLF)
                Sleep(500)
        WEnd
        FileSetPos($file,0,0)
WEnd
发表于 2012-12-1 22:16:37 | 显示全部楼层
回复  annybaby
afan也疼着呢,雨天打孩子呗,闲着也是闲着
netegg 发表于 2012-12-1 22:15



    心疼水贴…… 一次治愈~ ^ ^
发表于 2012-12-1 22:21:25 | 显示全部楼层
回复 27# annybaby
filesetpos跳回原点有必要吗,filereadline可以指定行号呀
发表于 2012-12-1 22:29:39 | 显示全部楼层
回复 29# netegg


    不同的方法而已`~~~
PS:楼主都不在了,就我们还在扯蛋~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-1 12:07 , Processed in 0.075229 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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