熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> ASP編程 >> 正文

VB.netini文件操作

2013-11-15 12:51:32  來源: ASP編程 

  以下內容放到vbnet中直接調用
Public Class ReadWriteIniClass
Private Declare Function GetPrivateProfileString Lib kernel Alias GetPrivateProfileStringA (ByVal lpApplicationName As String ByVal lpKeyName As String ByVal lpDefault As String ByVal lpReturnedString As String ByVal nSize As Int ByVal lpFileName As String) As Int
Private Declare Function WritePrivateProfileString Lib kernel Alias WritePrivateProfileStringA (ByVal lpApplicationName As String ByVal lpKeyName As String ByVal lpString As String ByVal lpFileName As String) As Int

  Private Declare Function GetPrivateProfileStringW Lib kernel Alias GetPrivateProfileStringW (ByVal lpApplicationName As String ByVal lpKeyName As String ByVal lpDefault As String ByVal lpReturnedString As String ByVal nSize As Int ByVal lpFileName As String) As Int
Private Declare Function WritePrivateProfileStringW Lib kernel Alias WritePrivateProfileStringW (ByVal lpApplicationName As String ByVal lpKeyName As String ByVal lpString As String ByVal lpFileName As String) As Int
mbcs
Public Shared Function GetINI(ByVal Section As String ByVal AppName As String ByVal lpDefault As String ByVal FileName As String) As String
Dim MyEncoder As SystemTextEncoding = SystemTextEncodingDefault
Dim chars() As Char
Dim strResult As String = New String(chars)
Dim length As Integer = GetPrivateProfileString(Section AppName lpDefault strResult Len(strResult) FileName)
編碼的轉換
Dim rByte() As Byte = SystemTextEncodingDefaultGetBytes(strResultToCharArray)
strResult = New String(MyEncoderGetChars(rByte))
Return MicrosoftVisualBasicLeft(strResult InStr(strResult Chr()) )
End Function
寫文件
Public Shared Function WriteINI(ByVal Section As String ByVal AppName As String ByVal lpDefault As String ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section AppName lpDefault FileName)
End Function

  unicode
Public Shared Function GetINIW(ByVal Section As String ByVal AppName As String ByVal lpDefault As String ByVal FileName As String) As String
Dim MyEncoder As SystemTextEncoding = SystemTextEncodingDefault
Dim strResult As String
Dim chars() As Char
strResult = CStr(chars)
GetPrivateProfileStringW(Section AppName lpDefault strResult Len(strResult) FileName)

  Dim rByte() As Byte = SystemTextEncodingDefaultGetBytes(strResultToCharArray)
strResult = New String(MyEncoderGetChars(rByte))
Return MicrosoftVisualBasicLeft(strResult InStr(strResult Chr()) )
End Function
寫文件
Public Shared Function WriteINIW(ByVal Section As String ByVal AppName As String ByVal lpDefault As String ByVal FileName As String) As Long
WriteINIW = WritePrivateProfileStringW(Section AppName lpDefault FileName)
End Function
End Class


From:http://tw.wingwit.com/Article/program/ASP/201311/21763.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.