CSDN看到的这个方法,感觉还不错。读取比较方便。
Code
原始链接地址如下:http://topic.csdn.net/t/20051011/12/4318889.html

Code
Imports System.IO
Public Class Form1
Function sdGetIniInfo(ByVal iniFile As String, ByVal iniSection As String) As String
If Not File.Exists(iniFile) Then
Return "文件 " & iniFile & " 未找到,请确认路径和文件名是否正确!"
Exit Function
End If
Dim iniRead As New StreamReader(iniFile)
Dim iniStr As String = iniRead.ReadToEnd
Dim i As Integer
Dim cLine As Integer
Dim noSec As Boolean = False
Dim getValue As String = ""
Dim cLst
cLst = iniStr.Split(Chr(13))
cLine = UBound(cLst)
For i = 0 To cLine
If cLst(i).indexof("=") > 0 Then
If cLst(i).split("=")(0).trim() = iniSection Then
noSec = True
getValue = cLst(i).split("=")(1).trim()
Exit For
End If
End If
Next
If noSec = True Then
Return getValue
Else
Return "没有找到 " & iniSection & " 的设置信息!"
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name As String
name = sdGetIniInfo(Application.StartupPath & "\set.ini", "name")
MsgBox(name)
End Sub
Code
Code