读书人

奇怪的有关问题 两个字符串比较的有关

发布时间: 2012-04-06 12:22:24 作者: rapoo

奇怪的问题 两个字符串比较的问题
If (Int(count) > 0) Then '判断是否有这条记录
idValue = String(255, 0))
tempIdValue = String(255, 0)
For I = 1 To Int(count)
tempIdName = "id " & I
GetprivateprofileString "config ", tempIdName, " ", idValue, 255, IniPath

idValue = idValue & "s "
'tempIdValue = LCase(idValue)
tempIdValue = UserName.Text & "s "
If tempIdValue = Trim(idValue) Then
flag = 1
End If

'MsgBox InStr(UserName.Text, tempIdValue)
MsgBox tempIdValue & "@ " & idValue
MsgBox Len(tempIdValue) & "@ " & Len(idValue)
MsgBox StrComp(tempIdValue, idValue)
'MsgBox Trim(UserName.Text) & "@ "

Next

idValue 先使用string 函数

GetprivateprofileString "config ", tempIdName, " ", idValue, 255, IniPath

是从ini文件里提取他的值

tempIdValue = UserName.Text 是textbox里的值

结果明明 两个值是一样的比如 都是 fzpj 比较起来却是不相等的
我用 MsgBox tempIdValue & "@ " & idValue 显示两个值也是一样的


我以为是String(255, 0)) 的问题
用 了tempIdValue = String(255, 0) 结果还是一样

后来一用 MsgBox Len(tempIdValue) & "@ " & Len(idValue)
才发现 Len(tempIdValue) 是4 Len(idValue)是255

可能是
GetprivateprofileString "config ", tempIdName, " ", idValue, 255, IniPath



是从ini文件里读取的问题吧

怎么样解决呢

怎么样来比较这两个字符串

[解决办法]
String(255, 0)) 的问题-----------肯定有问题啦
[解决办法]
想做什么呢?

两边都加trim
[解决办法]
idValue = idValue & "s "
改为:
idValue = trim(idValue) & "s "

[解决办法]
If trim(tempIdValue) = Trim(idValue) Then
试试看
[解决办法]
idValue 从数据堆栈里取得,把你设定的数据长度全部读出,当然有效数据一般都是在靠前的字节存放。
[解决办法]
GetprivateprofileString 返回值为取得的字符数,用它对字符串求 Left()

读书人网 >VB

热点推荐