以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [讨论]字符串空值  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=130876)

--  作者:wyz20130512
--  发布时间:2019/2/9 17:21:00
--  [讨论]字符串空值

Dim s As String

If s = "" Then

    Output.Show("".Length) \'输出正确

    Output.Show(s.Length) \'输出报错

End If


--  作者:有点甜
--  发布时间:2019/2/10 11:01:00
--  

Dim s As String
If s = Nothing Then
    msgbox("空值")
ElseIf s = "" Then
    msgbox("空字符串")
Else
    msgbox("正常")
End If


--  作者:wyz20130512
--  发布时间:2019/2/10 15:24:00
--  
Dim s As String
If s = "" Then
    msgbox("空字符串")
ElseIf s = Nothing Then
    msgbox("空值")
Else
    msgbox("正常")
End If

If s = Nothing Then
    msgbox("空值")
ElseIf s = "" Then
    msgbox("空字符串")
Else
    msgbox("正常")
End If

字符串的“空值”与“空字符串”是一回事吗?

--  作者:有点甜
--  发布时间:2019/2/10 15:59:00
--  

 

字符串来说,空值等于空字符串。

 

 


--  作者:wyz20130512
--  发布时间:2019/2/10 16:35:00
--  回复:(有点甜) 字符串来说,空值等于空字符...

对于字符串来说,空值等于空字符串,那问题来了。

Dim s As String

Output.Show("".Length)  \'正确输出

Output.Show(s.Length)  \'输出报错


--  作者:有点甜
--  发布时间:2019/2/10 17:38:00
--  

那你这样比较

 

Dim s As String
If s Is Nothing Then
    msgbox("空值")
ElseIf s = "" Then
    msgbox("空字符串")
Else
    msgbox("正常")
End If
 


--  作者:wyz20130512
--  发布时间:2019/2/10 19:40:00
--  
我想说的是:这可能是字符串的1个Bug.
--  作者:有点甜
--  发布时间:2019/2/10 20:48:00
--  

nothing的时候,不能直接使用方法。

 

空字符串不是nothing。

 

请用6楼代码判断值是不是nothing。