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

[系统综合] ini 写入格式问题`

  [复制链接]
发表于 2012-11-2 20:35:41 | 显示全部楼层 |阅读模式
本帖最后由 renren 于 2012-11-2 20:36 编辑


如何读取 txt 文件中这样 顺序的 数据,

再 写入 ini 文件 XX关键字 =  这样的格式

本帖子中包含更多资源

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

×
发表于 2012-11-2 21:07:58 | 显示全部楼层
Local $Str = _
                'SKZB01' & @CRLF & _
                ' SKZB03' & @CRLF & _
                ' SKZB76 ' & @CRLF & _
                'SKZB14t  ' & @CRLF & _
                '  SKzb52t' & @CRLF & _
                'servert  ' & @CRLF & @CRLF
MsgBox(0, '原字符串', $Str)
Local $sVal = StringRegExpReplace($str, '\h*\r\n\h*(?=\V)|(?<=\S)\s*$', ';')
MsgBox(0, '替换结果', $sVal)

IniWrite('test.ini', 'Uselist', 'maclist', $sVal)
发表于 2012-11-2 21:09:57 | 显示全部楼层

;读文件
$fileHandle = FileOpen(@ScriptDir & "\1.txt")
$buf = FileRead($fileHandle)
FileClose($fileHandle)

;拆分到数组
$array = StringSplit($buf, @CRLF, 1)

;再用分号拼接上
$buf = ""
For $i = 1 To $array[0] - 1
        $buf &= $array[$i] & ";"
Next
$buf &= $array[$i]

;写入Ini
IniWrite(@ScriptDir & "\2.ini", "Uselist", "maclist", $buf)
发表于 2012-11-2 21:14:11 | 显示全部楼层
本帖最后由 半芯竹 于 2012-11-2 21:17 编辑

回复 1# renren
真有点怀疑你是否版主。。
#include <File.au3>
Local $CountLines = _FileCountLines("1.txt")
Local $file = FileOpen("1.txt", 0)
Local $line[100],$temp
If $file = -1 Then
    MsgBox(4096, "错误", "不能打开文件.")
    Exit
EndIf
For $i =1 To $CountLines
     $line[$i] = FileReadLine($file)
    If @error = -1 Then ExitLoop
        $temp=$temp&$line[$i]&';'
Next
FileClose($file)
IniWrite(@ScriptDir&"\my.ini", "Uselist", "maclist", $temp)

你看下这是你要的效果么?

本帖子中包含更多资源

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

×
发表于 2012-11-3 00:43:01 | 显示全部楼层
回复  renren
真有点怀疑你是否版主。。

你看下这是你要的效果么?
半芯竹 发表于 2012-11-2 21:14


哈哈,这个有意思。
发表于 2012-11-3 13:46:50 | 显示全部楼层
回复 4# 半芯竹


    版主就要会AU3?我也不会AU3哇!
发表于 2012-11-3 13:58:52 | 显示全部楼层
A斑 是灌水来着
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 21:19 , Processed in 0.092424 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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