找回密码
 加入
搜索
查看: 3647|回复: 6

[AU3基础] 请教正则替换的问题【已解决】

  [复制链接]
发表于 2010-5-25 13:48:12 | 显示全部楼层 |阅读模式
本帖最后由 woeiwoei 于 2010-5-25 14:44 编辑


如何将 ini文件中 【VS】下的 所有数据的前6位替换为 制定字符??
例如 B703A65780C5 替换为 0000005780C5
所有数据哦~大虾们帮帮忙~

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-5-25 14:12:45 | 显示全部楼层
用不着正则吧
StringReplace (FileReadLine('数据.ini',$i), StringLeft(FileReadLine('数据.ini',$i), 6), "000000" )
 楼主| 发表于 2010-5-25 14:18:14 | 显示全部楼层
回复 2# dtooboss


    改不了。。。
发表于 2010-5-25 14:29:22 | 显示全部楼层
本帖最后由 dtooboss 于 2010-5-25 14:30 编辑
回复  dtooboss


    改不了。。。
woeiwoei 发表于 2010-5-25 14:18
$ini =_IniReadSection( '数据.ini','vs')
For $n = 1 To $ini[0][0] Step 1
        IniWrite('新数据.ini','vs', StringReplace($ini[$n][0], StringLeft($ini[$n][0], 6), "000000" ),$ini[$n][1])
Next        



Func _IniReadSection($iFile, $Section, $mode = 0); afan 斑竹的udf
        Local $_Section, $s_Sec, $s_zl, $ii = 1, $i
        Local $o_File = FileOpen($iFile, $mode)
        Local $s_File = String(FileRead($o_File))
        FileClose($o_File)
        $_Section = StringRegExpReplace('[' & $Section & ']', '(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)', '\\$1')
        $s_Sec = StringRegExp($s_File & @CRLF & '[', '(?s)(?i)' & $_Section & '(.+?)\r\n\[', 3)
        If @error Then Return SetError(1, 0, 0)
        $s_zl = StringRegExp($s_Sec[0], '\n\s*([^=;\s][^=\r\n]*)\=(.*)', 3)
        If @error Then Return SetError(2, 0, 0)
        Local $2_array[UBound($s_zl) / 2 + 1][2] = [[UBound($s_zl) / 2]]
        For $i = 0 To UBound($s_zl) - 1 Step 2
                $2_array[$ii][0] = $s_zl[$i]
                $2_array[$ii][1] = $s_zl[$i + 1]
                $ii += 1
        Next
        Return $2_array
EndFunc   ;==>_IniReadSection

评分

参与人数 1金钱 +9 贡献 +1 收起 理由
lynfr8 + 9 + 1

查看全部评分

发表于 2010-5-25 14:40:07 | 显示全部楼层
#Include <File.au3>
$FirstFile="data.ini"
$ResultFile="result.ini"
If FileExists($FirstFile) Then FileDelete($FirstFile)
IniWriteSection($FirstFile,"vs","")
If FileExists($ResultFile) Then FileDelete($ResultFile)
IniWriteSection($ResultFile,"vs","")
For $i=2 To 200 Step 1
        _FileWriteToLine($FirstFile,$i,Random(1000000000,9999999999,1),1)
Next
For $j=2 To _FileCountLines($FirstFile) Step 1
        $Line=FileReadLine($FirstFile,$j)
        $Line=StringReplace($Line,StringLeft($Line,6),"000000")
        _FileWriteToLine($ResultFile,$j,$Line,1)
Next
Run("notepad.exe "&$FirstFile)
Run("notepad.exe "&$ResultFile)

评分

参与人数 1金钱 +13 收起 理由
lynfr8 + 13

查看全部评分

 楼主| 发表于 2010-5-25 14:44:05 | 显示全部楼层
dtooboss 发表于 2010-5-25 14:29



    这个UDF 太强了。。非常感谢~~
 楼主| 发表于 2010-5-25 14:44:25 | 显示全部楼层
lanfengc 发表于 2010-5-25 14:40



    非常感谢、
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-3 15:23 , Processed in 0.087659 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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