繁体   English   中英

在 VB .NET 2012 中读取 INI 文件的部分

[英]Read sections of INI file in VB .NET 2012

你能帮我解决这个问题吗? 我想获取 INI 文件的部分名称和字段。 例子:

[connection]
server=localhost
user=root
password=root

我的程序应该返回部分名称和字段:连接服务器用户密码

提前致谢..

以防万一有人需要它。 这里是:

   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.

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