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

[AU3基础] 关于循环再循环问题求高手指教

[复制链接]
发表于 2011-12-2 02:16:24 | 显示全部楼层 |阅读模式
现在获取一个字符串为       192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%
我想将他以 IP  CPU  显卡 的格式写如到列表视图中

目前用
$11 = "192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%
"
$bb = StringTrimRight($nString,1)
$aa = StringSplit($bb,"%")
For $i = 1 To $aa[0]
        MsgBox (0, $i, $aa[$i]) ;-获得的值为    192.168.0.1|Amd|9600gt|    现在要将此结果插入到   $ListView1
        ;~     GUICtrlCreateListViewItem($aa[$i][$o][1] & '|' & $aa[$i][$o][2] & '|' & $aa[$i][$o][3] & '|' & $aa[$i][$o][4] , $ListView1)
Next
但貌似不正确。求高手给指点下。鄙人才接触AU3。。
发表于 2011-12-2 03:01:10 | 显示全部楼层
建议你把自己的相关代码发完整些...
看到一两个要猜测的变量,,我想别人和我一样,会看不下去吧?

评分

参与人数 1金钱 +10 收起 理由
afan + 10 我很赞同

查看全部评分

发表于 2011-12-2 06:38:18 | 显示全部楼层
回复 1# 49666684

用了正则.
$Str = '192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%'
$Test = StringRegExp($Str, '(.*?)%', 3)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
        Local $listview, $button, $input1, $msg, $Test, $Str
        Local $item[3]
        GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
        GUISetBkColor(0x00E0FFFF)

        $listview = GUICtrlCreateListView("列 1 |列 2|列 3  ", 10, 10, 200, 150);
        $button = GUICtrlCreateButton("Button", 40, 170, 120, 20)
        GUISetState()

        $Str = '192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%'
        $Test = StringRegExp($Str, '(.*?)%', 3)

        For $i = 0 To UBound($Test) - 1
                MsgBox(0, $i + 1, $Test[$i])
                $item[$i] = GUICtrlCreateListViewItem($Test[$i], $listview)

                _GUICtrlListView_SetColumnWidth($listview, $i, $LVSCW_AUTOSIZE)
        Next

        Do
                $msg = GUIGetMsg()

                Select
                        Case $msg = $button
                                MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
                EndSelect
        Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

评分

参与人数 1金钱 +30 收起 理由
afan + 30

查看全部评分

 楼主| 发表于 2011-12-2 12:04:17 | 显示全部楼层
3楼这个我测试了下。。。。但如果$Str = '192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%'

继续添加下去的话。也只能显示3条。为什么?
发表于 2011-12-2 12:40:52 | 显示全部楼层
回复 4# 49666684

$Str = '192.168.0.1|Amd|9600GT|%192.168.0.1|Amd|9600GT|%192.168.0.3|Intel|GTX250|%'
$Test = StringRegExp($Str, '(.*?)%', 3)

它能匹配192.168.0.3|Intel|GTX250|%这种形式(红色部分).
也就是说只能匹配3个.

你看看第24行和第11行,再看看帮助里面的Local,数组.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 21:29 , Processed in 0.080868 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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