溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

VB.NET如何讀取INI

發(fā)布時間:2021-11-30 15:48:15 來源:億速云 閱讀:534 作者:小新 欄目:編程語言

這篇文章主要介紹VB.NET如何讀取INI,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

雖然VB.NET中讀取XML配置信息很方便,但有時開發(fā)的過程中還是要用到INI文件,VB.NET讀取INI卻不像VB中那么方便了,剛才寫了個函數(shù),現(xiàn)貼出來,也許各位能用得上。

  1. Function sdGetIniInfo(ByVal iniFile As String, 
    ByVal iniSection As String) As String  

  2. If Not File.Exists(iniFile) Then  

  3. Return "文件 " & iniFile & " 未找到,請確認(rèn)路徑和文件名是否正確!"  

  4. Exit Function  

  5. End If  

  6.  

  7. Dim iniRead As New StreamReader(iniFile)  

  8. Dim iniStr As String = iniRead.ReadToEnd  

  9.  

  10. Dim i As Integer  

  11. Dim cLine As Integer  

  12. Dim noSec As Boolean = False 

  13. Dim getValue As String = "" 

  14. Dim cLst  

  15.  

  16. cLst = iniStr.Split(Chr(13))  

  17. cLine = UBound(cLst)  

  18.  

  19. For i = 0 To cLine  

  20. If cLst(i).indexof("=") > 0 Then  

  21. If cLst(i).split("=")(0).trim() = iniSection Then  

  22. noSec = True 

  23. getValue = cLst(i).split("=")(1).trim()  

  24. Exit For  

  25. End If  

  26. End If  

  27. Next  

  28.  

  29. If noSec = True Then  

  30. Return getValue  

  31. Else  

  32. Return "沒有找到 " & iniSection & " 的設(shè)置信息!"  

  33. End If  

  34. End Function 

說明:在引用的面頁中要先引用 Imports System.IO

set.ini文件內(nèi)容:

  1. Private Sub Button1_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles Button1.Click  

  2. Dim name As String  

  3. name = sdGetIniInfo(Application.StartupPath & "\set.ini", "name")  

  4. MsgBox(name)  

  5. End Sub  

以上是“VB.NET如何讀取INI”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI