简体   繁体   English

读/写“INI”文件

[英]Read/Write “INI” file

Evening Everyone - 每个人都 -

I'm looking for some thoughts on how to read / write values from a windows "ini" structured file. 我正在寻找关于如何从windows“ini”结构化文件中读取/写入值的一些想法。 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. 我使用buffer.replace进程工作但现在意识到某些键被分段使用并且全局替换值将导致问题。

Here is a sample of what my ini file looks like 这是我的ini文件的样子

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! 我有几十个块,所以任何关于在特定部分内完成读写值的清晰度都将非常感激!

--Cheers & Thanks George - 欢迎和感谢乔治

You can use some of the kernel32 functions. 您可以使用一些kernel32函数。

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

This will let you read an ini file 这将让您阅读ini文件

Dim sb As StringBuilder

sb = New StringBuilder(500)
GetPrivateProfileString("IMPORT-1", "SETTINGS", "", sb, sb.Capacity, "test.ini")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM