王王 发表于 2011-8-11 19:40:40

[已解决]请教下 写了个读TXT文件一行的3个段不清楚怎么循环读文本每一行的

本帖最后由 王王 于 2011-8-12 08:19 编辑

各位大侠帮看下先谢谢了

假如uuss.txt内容为
11111%11125522%2222445
kkkk   % kioll   % 554d    r
fdgfggdg% .;;;;, %645552
kkllklk%kjhhu       %   21525
......
.....
....
...
..
.



$Biaot1 = FileReadLine("D:\uuss.txt", 1)
$shuliang1 = StringInStr ( $Biaot1 , "%" , 0 ,1 )
$shuliang2 = StringInStr ( $Biaot1 , "%" , 0 ,2 )
$shuliang3 = StringInStr ( $Biaot1 , "%" , 0 ,3 )

$neirong1 = ($shuliang1)-1
$neirong2 = ($shuliang2)-1
$neirong3 = ($shuliang3)-1

$guanjianzi1 = ($shuliang1)+1
$guanjianzi2 = ($shuliang2)+1
$guanjianzi3 = ($shuliang3)+1

$weishu2 = ($shuliang2)-($guanjianzi1)
$weishu3 = ($shuliang3)-($guanjianzi2)

$result = StringMid ( $Biaot1, 1, $neirong1
$result2 = StringMid ( $Biaot1, $guanjianzi1, $weishu2)
$result3 = StringMid ( $Biaot1, $guanjianzi2, $weishu3)

$kongbai = StringStripWS($result,8)
$kongbai2 = StringStripWS($result2,8)
$kongbai3 = StringStripWS($result3,8)
MsgBox("","1内容",$result)
MsgBox("","2内容",$result2)
MsgBox("","3内容",$result3)
MsgBox("","1除空白内容",$kongbai)
MsgBox("","2除空白内容",$kongbai2)
MsgBox("","3除空白内容",$kongbai3)

powerofos 发表于 2011-8-11 19:49:21

我按捺住了性子看完了您的帖子,StringSplit()

王王 发表于 2011-8-11 20:20:37

我按捺住了性子看完了您的帖子,StringSplit()
powerofos 发表于 2011-8-11 19:49 http://www.autoitx.com/images/common/back.gif


    没看懂啊,老大
我每1行的3个值分别要赋予另外程序的对应的3个变量,另一个程序需要同时使用 1000行的3个值
怎么实现?我就循环那里卡着了头昏了

水木子 发表于 2011-8-11 20:31:27

确实没看明白你说的什么!

powerofos 发表于 2011-8-11 21:17:13

回复 3# 王王


既然我在论坛帮助板块也帮不了大忙,那就随便发个例子给你吧,BTW,多看帮助。#Include <File.au3>

Dim $Txt,$Open,$Close,$LineCount,$String,$SSplit,$StringEx

$Txt = @ScriptDir&"\test.txt"

$LineCount = _FileCountLines($Txt)
If @error Or $LineCount = 0 Then Exit

$Open = FileOpen($Txt)
For $i = 1 To $LineCount
        $String = FileReadLine($Open,$i)
        If @error Then ExitLoop
        $SSplit = StringSplit($String,"%")
        If @error Then
                MsgBox(0,"Error","行"&$i&"未发现分隔符")
        Else
                $StringEx = "元素数量"
                For $Ele In $SSplit
                        $StringEx = $StringEx&$Ele&@CRLF
                Next
                MsgBox(0,"Success","行:"&$i&@CRLF&$StringEx)
        EndIf
Next       
FileClose($Open)

王王 发表于 2011-8-12 08:15:09

回复王王


既然我在论坛帮助板块也帮不了大忙,那就随便发个例子给你吧,BTW,多看帮助。
powerofos 发表于 2011-8-11 21:17 http://www.autoitx.com/images/common/back.gif


    谢谢powerofos 了这个运行错误了
我早上起来想起 才发现昨天进牛角尖了,直接加循环就可以了

$i = 0
do$Biaot1 = FileReadLine("D:\uuss.txt", $i)
$shuliang1 = StringInStr ( $Biaot1 , "%" , 0 ,1 )
$shuliang2 = StringInStr ( $Biaot1 , "%" , 0 ,2 )
$shuliang3 = StringInStr ( $Biaot1 , "%" , 0 ,3 )

$neirong1 = ($shuliang1)-1
$neirong2 = ($shuliang2)-1
$neirong3 = ($shuliang3)-1

$guanjianzi1 = ($shuliang1)+1
$guanjianzi2 = ($shuliang2)+1
$guanjianzi3 = ($shuliang3)+1

$weishu2 = ($shuliang2)-($guanjianzi1)
$weishu3 = ($shuliang3)-($guanjianzi2)

$result = StringMid ( $Biaot1, 1, $neirong1
$result2 = StringMid ( $Biaot1, $guanjianzi1, $weishu2)
$result3 = StringMid ( $Biaot1, $guanjianzi2, $weishu3)

$kongbai = StringStripWS($result,8)
$kongbai2 = StringStripWS($result2,8)
$kongbai3 = StringStripWS($result3,8)
MsgBox("","1内容",$result)
MsgBox("","2内容",$result2)
MsgBox("","3内容",$result3)
MsgBox("","1除空白内容",$kongbai)
MsgBox("","2除空白内容",$kongbai2)
MsgBox("","3除空白内容",$kongbai3)
$i = $+1
until $i = 1000


你这个例子我下去理解理解 谢谢了
页: [1]
查看完整版本: [已解决]请教下 写了个读TXT文件一行的3个段不清楚怎么循环读文本每一行的