[英]Read sections of INI file in VB .NET 2012
Can you help me on this?你能帮我解决这个问题吗? I want to get the section name and fields of my INI file.我想获取 INI 文件的部分名称和字段。 Example:例子:
[connection]
server=localhost
user=root
password=root
My program should return the section name and the fields: connection server user password我的程序应该返回部分名称和字段:连接服务器用户密码
Thanks in advance..提前致谢..
Just in case someone needs it.以防万一有人需要它。 Here it is:这里是:
Dim path As String = Application.StartupPath & "\path_to_file"
' get a list of the files in this directory
' -----------------------------------------
Dim file_list As String() = Directory.GetFiles(path, "*.ini")
' go through the list of files
' -------------------------------------------------------------------
For Each f As String In file_list
Dim a = New System.IO.FileInfo(f).Name
' open the file and read it
' -------------------------
Dim sr As StreamReader = New StreamReader(f)
' read through the file line by line
' -----------------------------------
Do While sr.Peek() >= 0
Dim temp_name = Split(sr.ReadLine(), "=")
first_part = temp_name(0)
second_part = temp_name(1)
' do something with the information here
Loop
sr.Close()
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.