找回密码
 加入
搜索
查看: 3209|回复: 7

[网络通信] [解决]2维数组判断,求纠正!

[复制链接]
发表于 2011-7-17 13:03:04 | 显示全部楼层 |阅读模式
本帖最后由 haebong87 于 2011-7-17 18:48 编辑

Item_tc.txt 文档中如果是5行的情况的话会多判断一次,5行的话应该判断4次才对的,求一个更好的方法来判断。
#include <array.au3>
 
$txt=FileOpen("item_tc.txt",0)
$b=0
While 1
$line = FileReadLine($txt)
If @error = -1 Then ExitLoop

Local $arr_master=StringSplit($line,@CRLF,2+1)
Local $cols=StringSplit(StringTrimRight($arr_master[0],1),"|",2)
$cols=UBound($cols)
Local $array[UBound($arr_master)][$cols]
for $i=0 to UBound($arr_master)-1
        $temp=StringSplit(StringTrimRight($arr_master[$i],1),"|",2)
        for $n=0 to UBound($temp)-1
                $array[$i][$n]=$temp[$n]
        Next
Next

$a = $array[0][1]
If $a <> $b Then
        MsgBox(0,"不等于", $a &"不等于" & $b)
ElseIf $a = $b then
        MsgBox(0,"等于",$a &"等于" & $b)
EndIf
$b=$a
WEnd
 楼主| 发表于 2011-7-17 13:05:59 | 显示全部楼层
Item_tc.txt 是这种格式,小弟不会上传这个txt格式的文本。
所以将里面内容粘贴在这里了。
头盔|1|1|2450|50|32|1|战士头盔|1|1|2517|50|32|1|
铠甲|2|1|2517|2|32|2|
臂铠|3|1|2575|5|140|1|
护腿|3|1|2575|5|140|1|
战靴|2|1|2575|5|140|1|
发表于 2011-7-17 15:45:04 | 显示全部楼层
没看明白楼主的问题是什么
发表于 2011-7-17 16:04:17 | 显示全部楼层
是不是你没注意最后一行有个回车 增加了一个空行
发表于 2011-7-17 16:19:35 | 显示全部楼层
#include <array.au3>



$txt = FileOpen("item_tc.txt", 0)

$b = -1

While 1
        $line = FileReadLine($txt)
        If @error Then ExitLoop
        Local $arr_master = StringSplit($line, @CRLF, 2 + 1)
        Local $cols = StringSplit(StringTrimRight($arr_master[0], 1), "|", 2)
        $cols = UBound($cols)
        Local $array[UBound($arr_master)][$cols]
        For $i = 0 To UBound($arr_master) - 1
                $temp = StringSplit(StringTrimRight($arr_master[$i], 1), "|", 2)
                For $n = 0 To UBound($temp) - 1
                        $array[$i][$n] = $temp[$n]
                Next
        Next
        $a = $array[0][1]
        If $b = -1 Then
                Else
                If $a <> $b  Then
                        MsgBox(0, "不等于", $a & "不等于" & $b)
                Else
                        MsgBox(0, "等于", $a & "等于" & $b)
                EndIf
        EndIf
        $b = $a
WEnd
 楼主| 发表于 2011-7-17 18:47:14 | 显示全部楼层
我2楼的帖子是5行,但是运行的话会会判断6次,$a=$b因为这个,$a读取0的时候下面$b=$a所以会多判断一次。
 楼主| 发表于 2011-7-17 18:48:16 | 显示全部楼层
回复 5# lainline


    非常感谢!!! 学到了。。
发表于 2011-7-17 20:44:26 | 显示全部楼层
回复 7# haebong87
你学习到什么了?
#include <array.au3>
 
;~ $txt="苹果|1|2|"&@CRLF _
;~ &"西瓜|1|3|"&@CRLF _
;~ &"香蕉|2|4|"

$txt=FileRead("Item_tc.txt")
;====将字符串定义成多维数组====
Local $arr_master=StringSplit($txt,@CRLF,2+1)
If @error Then Exit
Local $cols=StringSplit(StringTrimRight($arr_master[0],1),"|",2)
$cols=UBound($cols)
Local $array[UBound($arr_master)][$cols]
for $i=0 to UBound($arr_master)-1
        $temp=StringSplit(StringTrimRight($arr_master[$i],1),"|",2)
        for $n=0 to UBound($temp)-1
                $array[$i][$n]=$temp[$n]
        Next
Next
_ArrayDisplay($array)
;====定义数组结束====
 
;====判断====
for $i=0 to UBound($array)-2
        ;for $n=0 to UBound($array,2)-1
                if $array[$i][1]=$array[$i+1][1] then 
                        msgbox(0x40000,"",$array[$i][1]&" = " & $array[$i+1][1])
                Else
                        msgbox(0x40000,"",$array[$i][1]&ChrW(8800) & $array[$i+1][1])
                EndIf
        ;Next
Next
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-27 00:56 , Processed in 0.082639 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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