找回密码
 加入
搜索
查看: 2801|回复: 2

[效率算法] 连续从指定本文中查找指定的字符

  [复制链接]
发表于 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")
EndIf
config.dat中的内容

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


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

但怎么也读不出来
请高手指点下
发表于 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")
EndIf
config.dat的内容写成这样,以“|”间隔~
[配置信息]
禁止列表=可是|找对|021
发表于 2011-3-4 14:58:31 | 显示全部楼层
本帖最后由 lixiaolong 于 2011-3-4 21:25 编辑

1.
Global $inipath = @ScriptDir & "\config.dat"
$file = @SystemDir & "\UDO.log"
Dim $Name[100]
$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=021
2.
$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
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-4 06:25 , Processed in 0.077732 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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