asp中字符串转化为实体类的方法(优化篇,简单优化)
option explicit
dim str1,str2
str1 ="order|||shiyang:100,mayang:200"
str2 = "book|||shuming:计算机,dingjia:100"
'声明2个全局对象
'放弃了一开始希望用数组存储的方式,那个虽然效率更高,但是需要自定义的array_pushobj函数,所以此处不做讨论了
dim objname_g
dim classname_g
'返回实体类
function getObjmod(byval str)
dim classname,itemlist,i
dim execstr
classname = split(str,"|||")(0)
execstr = "class "&classname&chr(10)
itemlist = split(split(str,"|||")(1),",")
for i = 0 to ubound(itemlist)
execstr = execstr +"public "&split(itemlist(i),":")(0)&chr(13)&chr(10)
next
execstr = execstr&"end class"&chr(13)&chr(10)&_
" set objname_g = new "&classname
classname_g =classname
execute execstr
end function
'赋值
function getobjcon(byval str)
dim itemlist,i,execstr
if classname_g = split(str,"|||")(0) and isobject(objname_g) then
set getobjcon = objname_g
else
getObjmod( str)
set getobjcon = objname_g
end if
itemlist = split(split(str,"|||")(1),",")
for i = 0 to ubound(itemlist)
execstr = execstr +"getobjcon."&split(itemlist(i),":")(0)&" = """&split(itemlist(i),":")(1)&"""" &chr(13)&chr(10)
next
execute execstr
end function
'测试函数
sub ceshi3
dim i,o1
for i = 0 to 10000
set o1 = getobjcon(str1)
response.write o1.shiyang&"<br>"
next
set o1 = getobjcon(str2)
response.write o1.shuming&"<br>"
end sub
dim t1
t1=timer()
call ceshi3
response.write FormatNumber((timer()-t1),4,-1)
相关文档:
<bgsound src="wen.mid" loop="0">
<% dim weh
If Time >=#1:00:00 AM# And Time < #6:00:00 PM# Then
weh = "<bgsound src="1.mid" loop="0">"
Else If Time >#6:00:00 AM# And Time < #9:00:00 PM#
weh = "<bg ......
Abs (数值)
绝对值。一个数字的绝对值是它的正值。空字符串 (null) 的绝对值,也是空字符串。未初始化的变数,其绝对为 0
例子:ABS(-2000)
结果:2000
Array (以逗点分隔的数组元素)
Array 函数传回数组元素的值。
例子:
A=Array(1,2,3)
B=A(2)
结果: 2
说明:变量B为A数组的第二个元素的值。
As ......
用ASP编写网站应用程序时间长了,难免会遇到各式各样的问题,其中关于如何上传文件到服务器恐怕是遇见最多的问题了,尤其是上传图片,比如你想要在自己的社区里面实现类似网易虚拟社区提供的“每日一星”的功能,就要提供给网友上传照片的功能。上传图片文件到服务器可以使用各种免费的文件上传组件,使 ......
ASP(Active Server Pages)是Microsoft很早就推出的一种WEB应用程序解决方案,也是绝大多数从事网站开发人员很熟悉的一个比较简单的编程环境。通过ASP我们可以创建功能强大的动态的WEB应用程序。ASP虽然功能很强大,但有些功能用纯ASP代码完成不了,为了能保证开发出功能更加强大的WEB应用程序,我们可以借助调用COM组件。 ......
<bgsound src="wen.mid" loop="0">
<% dim weh
If Time >=#1:00:00 AM# And Time < #6:00:00 PM# Then
weh = "<bgsound src="1.mid" loop="0">"
Else If Time >#6:00:00 AM# And Time < #9:00:00 PM#
weh = "<bgso ......