找回密码
 加入
搜索
查看: 10463|回复: 30

[效率算法] 文本有条件替换...... [已解决]

 火.. [复制链接]
发表于 2012-3-20 10:56:46 | 显示全部楼层 |阅读模式
本帖最后由 流沙枫 于 2012-3-20 15:27 编辑

add caller-id="" comment="\C5\A9\BD\F0\C3\F4" disabled=no limit-bytes-in=0 \
    limit-bytes-out=0 name=201109password=201109 profile=default \
    routes="" service=pppoe
add caller-id="" comment="\D6\A3\BE\DE\C9\CD" disabled=no limit-bytes-in=0 \
    limit-bytes-out=0 name=201112 password=201103 profile=default \
    routes="" service=pppoe

按下面的条件替换文本.....
name=i password=j
if i=j
then disabled=no 改为 disabled=yes

求助大大们啊.....
就是如果用户名和密码相同,就禁用掉这个帐号!

评分

参与人数 1金钱 +15 收起 理由
afan + 15 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2012-3-20 11:00:14 | 显示全部楼层
。。。不知道你在自言自语什么呢。

评分

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

查看全部评分

发表于 2012-3-20 12:29:12 | 显示全部楼层
楼主看看下面的代码,你是不是这个意思啊(假设ADD为头的每一句话内容在一行上,文件为1.txt)
FileCopy(@ScriptDir & "\1.txt", @TempDir & "\1.txt",1)
$File = FileOpen(@TempDir & "\1.txt", 0)
$nFile = FileOpen(@ScriptDir & "\1.txt", 2)
While 1
        $Var = FileReadLine($File)
        If @error = -1 Then ExitLoop
        $name = StringRegExp($Var, "name=(\d{6}) ", 3)
        $password = StringRegExp($Var, "password=(\d{6}) ", 3)
        If $name[0] = $password[0] Then
                $Var = StringReplace($Var, "disabled=no", "disabled=yes")
        EndIf
        FileWriteLine($nFile, $Var)
WEnd
FileClose($File)
FileClose($nFile)
ShellExecute("1.txt")
发表于 2012-3-20 12:31:48 | 显示全部楼层
不明所以,就不能说明白点?
 楼主| 发表于 2012-3-20 13:35:15 | 显示全部楼层
回复 2# nmgwddj


    就是如果用户名和密码相同,就禁用掉这个帐号
 楼主| 发表于 2012-3-20 13:35:22 | 显示全部楼层
不明所以,就不能说明白点?
xms77 发表于 2012-3-20 12:31



    就是如果用户名和密码相同,就禁用掉这个帐号
 楼主| 发表于 2012-3-20 13:40:30 | 显示全部楼层
楼主看看下面的代码,你是不是这个意思啊(假设ADD为头的每一句话内容在一行上,文件为1.txt)
shqf 发表于 2012-3-20 12:29



    就是这个意思,大大给力啊....
可惜运行还有错误
Subscript used with non-Array variable.:
If $name[0] = $password[0] Then
If $name^ ERROR

还有不是一行,是三行一组的......
 楼主| 发表于 2012-3-20 13:45:42 | 显示全部楼层
回复 3# shqf


拜谢啊.....
发表于 2012-3-20 13:58:21 | 显示全部楼层
本帖最后由 afan 于 2012-3-20 14:58 编辑

正则替换只需一行…
$sReplace = StringRegExpReplace($str, '(?i)disabled=no(.+\s+.+name=\h*(\H.+?)\h*password=\h*\2)', 'disabled=yes$1')
发表于 2012-3-20 14:01:55 | 显示全部楼层
本帖最后由 afan 于 2012-3-20 14:58 编辑
Local $Str = _
                'add caller-id="" comment="\C5\A9\BD\F0\C3\F4" disabled=no limit-bytes-in=0 \' & @CRLF & _
                '    limit-bytes-out=0 name=201109password= 201109profile=default \' & @CRLF & _
                '    routes="" service=pppoe' & @CRLF & _
                'add caller-id="" comment="\D6\A3\BE\DE\C9\CD" disabled=no limit-bytes-in=0 \' & @CRLF & _
                '    limit-bytes-out=0 name=201112 password=201103 profile=default \' & @CRLF & _
                '    routes="" service=pppoe' & @CRLF & @CRLF
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExpReplace($str, '(?i)disabled=no(.+\s+.+name=\h*(\H.+?)\h*password=\h*\2)', 'disabled=yes$1')
MsgBox(0, '替换结果', $Test)
发表于 2012-3-20 14:07:18 | 显示全部楼层
看得晕死了,楼主说得很不清楚啊~
 楼主| 发表于 2012-3-20 14:24:19 | 显示全部楼层
正则替换只需一行…
afan 发表于 2012-3-20 13:58



    太感谢了,再弱弱的问下,这个正则怎么用?放在autoit 里都编译出错的?
发表于 2012-3-20 14:25:37 | 显示全部楼层
回复 12# 流沙枫


    10#的可以直接运行测试~
 楼主| 发表于 2012-3-20 14:35:20 | 显示全部楼层
afan 发表于 2012-3-20 14:01



    可以了,不过得结合上一个代码,才好读取文件修改了....
只能再自己努力研究下。
发表于 2012-3-20 14:38:47 | 显示全部楼层
可以了,不过得结合上一个代码,才好读取文件修改了....
只能再自己努力研究下。
流沙枫 发表于 2012-3-20 14:35



    不会吧,这是方便测试的例子(不用另外创建个文本再读取),实际应用的话只需将 Local $Str = 你获取字符串的方式。
如 Local $Str = FileRead('test.txt')
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-6 16:48 , Processed in 0.099804 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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