当前位置:首页 > ASP教程 > 应用技巧

ASP 空字符串、IsNull、IsEmpty区别分析

说明:set aa=server.createobject("ddd")
isnull 说明指针为空,指针指到一个无效的位置,即对象不存在,
isempty 说明指针指向一个有效位置,但是值为空

1、空字符串
例:
复制代码 代码如下:

a)dim strtmp
response.write(strtmp="") ' 返回true
b)response.write(str="") ' 返回 true
c)dim strtmp
strtmp=""
response.write(strtmp="") ' 返回 true

这几行代码说明asp中无论是没做过声明的变量还是做个声明但没有赋值的变量asp都认为是空字符串或叫做零长度字符串。

2、isempty()
如果变量未初始化或显式地设置为 empty,则函数 isempty 返回 true;
否则函数返回 false。如果 expression 包含一个以上的变量,总返回 false。
例:
复制代码 代码如下:

a)dim strtmp
response.write(isempty(strtmp)) ' 返回 true
b)dim strtmp
strtmp = null
response.write(isempty(strtmp)) ' 返回 flase
c)dim strtmp
strtmp = empty
response.write(isempty(strtmp)) ' 返回 true
d)dim strtmp
strtmp = ""
response.write(isempty(strtmp)) ' 返回 flase

3、isnull()
null 值指出变量不包含有效数据。null 与 empty 不同,后者指出变量未经初始化。null 与零长度字符串 ("") 也不同,零长度字符串往往指的是空串。
使用 isnull 函数可以判断表达式是否包含 null 值。
例:
复制代码 代码如下:

a)dim strtmp
response.write(isnull(strtmp)) ' 返回 false
b)response.write(isnull(strtmp)) ' 返回 false 注意这里strtmp是一个未经声明的变量
a)dim strtmp
strtmp = null
response.write(isnull(strtmp)) ' 返回 true
a)dim strtmp
strtmp = empty
response.write(isnull(strtmp)) ' 返回 false

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!