shounei 发表于 2011-3-3 17:37:11

连续从指定本文中查找指定的字符

下面的代码可以查找,高手能否优化改进一下Global $inipath = @ScriptDir & "\config.dat"
$file = @SystemDir& "\UDO.log"
$Name1 = IniRead($inipath, "配置信息", "禁止列表1", "")
$Name2 = IniRead($inipath, "配置信息", "禁止列表2", "")
$Name3 = IniRead($inipath, "配置信息", "禁止列表3", "")
If StringInStr(FileRead($file), $Name1) Then
    Msgbox(0, "", "Found")
Else
    Msgbox(0, "", "Not Found")
EndIf
If StringInStr(FileRead($file), $Name2) Then
    Msgbox(0, "", "Found")
Else
    Msgbox(0, "", "Not Found")
EndIf
If StringInStr(FileRead($file), $Name3) Then
    Msgbox(0, "", "Found")
Else
    Msgbox(0, "", "Not Found")
EndIfconfig.dat中的内容

[配置信息]
禁止列表1=可是
禁止列表2=找对
禁止列表3=021


本来想把config.dat的内容写成这样
[配置信息]
禁止列表=可是,找对,021

但怎么也读不出来
请高手指点下

afan 发表于 2011-3-3 20:47:26

$inipath = @ScriptDir & "\config.dat"
$file = @SystemDir& "\UDO.log"
$Name = IniRead($inipath, "配置信息", "禁止列表", "")
If StringRegExp(FileRead($file), $Name) Then
        MsgBox(0, "", "Found")
Else
        MsgBox(0, "", "Not Found")
EndIfconfig.dat的内容写成这样,以“|”间隔~[配置信息]
禁止列表=可是|找对|021

lixiaolong 发表于 2011-3-4 14:58:31

本帖最后由 lixiaolong 于 2011-3-4 21:25 编辑

1.Global $inipath = @ScriptDir & "\config.dat"
$file = @SystemDir & "\UDO.log"
Dim $Name
$s = 0
For $i = 1 To 100
        $Name[$s] = IniRead($inipath, "配置信息", "禁止列表" & $i, "")
        If Not $Name[$s] Then ExitLoop
        If StringInStr(FileRead($file), $Name[$s]) Then
                MsgBox(0, $Name[$s], "Found")
        Else
                MsgBox(0, $Name[$s], "Not Found")
        EndIf
        $s += 1
Next[配置信息]
禁止列表1=可是
禁止列表2=找对
禁止列表3=0212.$inipath = @ScriptDir & "\config.dat"
$file = @SystemDir & "\UDO.log"
$Name = IniRead($inipath, "配置信息", "禁止列表", "")
$Lsit = StringSplit($Name, ',')

For $i = 1 To UBound($Lsit) - 1
      If StringInStr(FileRead($file), $Lsit[$i]) Then
                MsgBox(0, $Lsit[$i], "Found")
      Else
                MsgBox(0, $Lsit[$i], "Not Found")
      EndIf
Next[配置信息]
禁止列表=可是,找对,021
页: [1]
查看完整版本: 连续从指定本文中查找指定的字符