asp中变量用法及response.write方法总结
变量使用规范过程:定义→赋值→引用→输出
response.write:向客户端输出
-response.write 变量数据或字符串
-<%=变量数据或字符串%>
-response.write "您是第" & a & "次访问,您好!"
-<%="您是第" & a & "次访问,您好!"%>
-resonse.write内的htm标记语言会自动被ie执行!
-response.write "<a href="/blog/www.sina.com.cn">新浪</a>"
一、算术运算符的运用(较简单!)
例1:
<%
dim a,b,c '定义变量
a=1 '给变量赋值
b=2
c=a+b '引用变量
●response.write c 'response用法一:输出变量c(数值型)
%>
例2:
<%
Dim a(2) '定义数组,数组就是排列在一起的一组变量
a(0)=1 '赋值
a(1)=2
a(2)=3
sum=a(0)+a(1)+a(2) '引用数组
response.write sum
%>
例3:
<%
Dim a(2,2) '定义二维数组
a(0,0)=10 '赋值
a(0,1)=20
a(0,2)=30
sum=a(0,0)+a(0,1)+a(0,2) '引用数组
response.write sum
%>
二、比较运算符应用(掌握)
例4:
<%
Dim a,b,c '定义变量
a=2 '赋值
b=3
●c=a>b 'a>b是比较运算,将运算结果(逻辑值:true,false)赋给c
● response.write c 'response用法二:输出变量c(逻辑型)
%>
三、逻辑运算符(掌握)
例5:
<%
Dim a,b,c '定义变量
a=2 '赋值
b=3
●c=a>1 And b<2 'a>1的结果为true,b<2结果为false;两者and的结果为false
response.write c
%>
需要重点掌握的常见逻辑运算:
and a>2 and b<3
or a=2 or b<3
not not a>2 <=> a<=2
四、连接运算(重点掌握!!)
例6:
<%
Dim a,b,c
a="我是"
b="超人!"
c=a & b '连接运算
●response.write c 'response用法三:输出字符变量c
%>
●☆例7:
<%
Dim a,b,c
a=1
b=2
c=a+b
●response.write "a+b=" & c 'reponse用法四:输出连接运算结果
%>
●☆例8:
<%
Dim n,y,r,sj
n=Year(Date())
y=Month(Date())
r=Day(Date())
●sj="您来访的时间是:" & n & "年" & y & "月" & r & "日" '字符串与变量的连接运算
response.write sj
%>
连接运算总结:
☆c="我是" & "超人!"
☆c="我是" & b
☆sj="您来访的时间是:" & n & "年" & y & "月" & r & "日"
●response.write "a+b=" & Cstr(c)
●response.write c & "<p>"
字符串函数:
c=left("abcd",2) '从左边开始取2个字符
c=right("abcd",2)'从右边取
c=len("abcd") '获取字符串长度
c=trim("abcd ") '去掉字符串两边的空格
c=split("ab/cd/ef","/") '拆分函数,用 “/”拆分前面的字符串
c=instr("ab","ab") '查找函数
日期函数:
date()
- 上一篇:相应国家号召 肃清网站环境
- 下一篇:男护士专用邮箱增加审核状态查询模块