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

[效率算法] 关于非数组变量的错误,谁可以帮我纠正一下?[已解决]

[复制链接]
发表于 2011-7-14 20:50:30 | 显示全部楼层 |阅读模式
本帖最后由 haebong87 于 2011-7-14 22:02 编辑

如题,求纠正,在这个基础上修改一下可以吗?
$file = fileopen("test.txt",0)
dim $n=1
$str = filereadline($file,$n)
$nums=stringregexp($str,'.+?\|\d+\|(\d+)',3)
$nums1=stringregexp(filereadline($file,$n+1),'.+?\|\d+\|(\d+)',3)
$result = StringCompare($nums[1],$nums1[1])
If $result=0then
msgbox(0,"Test","false")
elseif $result <>0  then
msgbox(0,"Test","Ture")
endif
下面是3mile老师给我修改的,但是由于本人刚入门,还看不懂能否帮我解释一下?这个太复杂了。
#include <array.au3>
 
$txt="苹果|1|2|"&@CRLF _
&"西瓜|1|3|"&@CRLF _
&"香蕉|2|4|"
 
;====将字符串定义成多维数组====
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][$n]=$array[$i+1][$n] then 
                        msgbox(0x40000,"",$array[$i][$n]&" = " & $array[$i+1][$n])
                Else
                        msgbox(0x40000,"",$array[$i][$n]&ChrW(8800) & $array[$i+1][$n])
                EndIf
        Next
Next
下面的一段是将每一个数组都进行对比,但是我需要的是将每一行的第一个分隔符后面的数组进行对比,然后得出结果。
 楼主| 发表于 2011-7-14 20:56:35 | 显示全部楼层
坐等纠正。。。。。
发表于 2011-7-14 21:45:13 | 显示全部楼层
#include <array.au3>

$txt="苹果|1|2|"&@CRLF _
&"西瓜|1|3|"&@CRLF _
&"香蕉|2|4|"

;====将字符串定义成多维数组====
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
发表于 2011-7-14 21:47:02 | 显示全部楼层
回复 2# haebong87


    在坐等的时间里,按按F1看看帮助就知道了
上面3Smile的代码没有什么复杂的呀,都是最基本的代码,你还要别人怎么帮你呢?
每行都给你注释下?
 楼主| 发表于 2011-7-14 22:06:16 | 显示全部楼层
谢谢谢谢,那我之前写的哪里有问题能解释一下么?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-6 10:02 , Processed in 0.078264 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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