作者sakiman (MW221U)
看板Visual_Basic
标题[.NET] 快速取得.ini里所有section?
时间Sat Jul 2 01:59:58 2011
写了一种不是很有效率捉取ini下,所有section的处理方式
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
sSection = vbNullString
sKey = vbNullString
sinifilename = Application.StartupPath & "\ERPTOP.ini"
If Not FileExistOrNot(sinifilename) Then Exit Sub
Dim tempStr As String
Dim StrList = New Collection
Dim exitFor As Integer
exitFor = 0
sKeyValue = Space(65536)
lReturnLen = GetPrivateProfileString(sSection, _
sKey, "", sKeyValue, 32768, sinifilename)
tempStr = ""
For i = 0 To 65536
'连续2次值为nothing代表已读完最後一个section
If (exitFor = 1) And _
(sKeyValue.ToCharArray()(i) = Nothing) Then
MsgBox(i)
Exit For
Else
exitFor = 0
End If
If (sKeyValue.ToCharArray()(i) <> "") And _
(sKeyValue.ToCharArray()(i) <> Nothing) Then
tempStr = tempStr + sKeyValue.ToCharArray()(i)
End If
If sKeyValue.ToCharArray()(i) = Nothing Then
'MsgBox(tempStr)
StrList.Add(tempStr) '每组完一个section,就丢StrList
tempStr = "" '清空组section的temp
exitFor = 1
End If
Next
'显示最後一个section
MsgBox(StrList.Item(StrList.Count)) '捉最後一个section的名称
End Sub
ini内容多时候,真的挺慢的,因为一个字元一个字元去串,
虽然成功捉到所有section,但超级慢.
各位前辈们,该如何改善它呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.168.66
※ 编辑: sakiman 来自: 220.135.168.66 (07/02 02:04)