读/写"INI".文件 [英] Read/Write "INI" file
问题描述
每个人晚上-
我正在寻找有关如何从Windows"ini"结构化文件中读取/写入值的想法.我有一个使用其他应用程序创建的设置文件,我想更新指定部分中的键值.我使用buffer.replace进程使它工作,但是现在意识到部分中使用了某些键,并且全局替换值会导致问题.
I'm looking for some thoughts on how to read / write values from a windows "ini" structured file. I have a settings file created with another application and I would like to update values of a key within a specified section. I got it working using a buffer.replace process but now realize that some keys are used over in sections and globally replacing a value will cause problems.
这是我的ini文件外观的一个示例
Here is a sample of what my ini file looks like
IMPORT-1]
SETTINGS="HELLO"
FILENAME="C:\TEST\TEST1.CSV"
[ENCODE-2]
FILENAME="C:\TEST\REPORT1.XPS"
我有几十个块,因此非常感谢您在特定部分内完成对值的读写操作!
I've got dozens of blocks so any clarity on accomplishing a read and write of a value within a specific section would be hugely appreciated!
-干杯谢谢 乔治
推荐答案
您可以使用一些kernel32函数.
You can use some of the kernel32 functions.
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As StringBuilder, _
ByVal nSize As Integer, _
ByVal lpFileName As String) As Integer
这将使您读取ini文件
This will let you read an ini file
Dim sb As StringBuilder
sb = New StringBuilder(500)
GetPrivateProfileString("IMPORT-1", "SETTINGS", "", sb, sb.Capacity, "test.ini")
这篇关于读/写"INI".文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!