我不喜欢用系统注册表,所以在VB中用INI文件存储信息,但是处理中文是,读ini得到的字符串后不能接其它的字符串.请教如何处理?abc.ini 文件中有
[title]
str=发包Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongFunction ReadIni(title As String, KeyName As String, DefauleValue As String, filename As String) As String '读出ini文件
Dim Ret As String, NC As Long
Ret = String(255, 0)
NC = GetPrivateProfileString(title, KeyName, DefauleValue, Ret, 255, filename)
If NC <> 0 Then Ret = Left$(Ret, NC)
ReadIni = Ret
End Function
s=readini("title","str","大案","abc.ini")
msgbox ( "A" & s & "A")
显示: A发包
而不是:A发包A
[title]
str=发包Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongFunction ReadIni(title As String, KeyName As String, DefauleValue As String, filename As String) As String '读出ini文件
Dim Ret As String, NC As Long
Ret = String(255, 0)
NC = GetPrivateProfileString(title, KeyName, DefauleValue, Ret, 255, filename)
If NC <> 0 Then Ret = Left$(Ret, NC)
ReadIni = Ret
End Function
s=readini("title","str","大案","abc.ini")
msgbox ( "A" & s & "A")
显示: A发包
而不是:A发包A
这样的到的字符串的最后全部是 chr(0) 的字符
你应该+上这样的处理
ret=trim(replace(ret,chr(0)," "))
这样就可以了
因为 chr(0)字符在VB中是结束符号 不能进行连接