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)
相关文档:
Abs (数值)
绝对值。一个数字的绝对值是它的正值。空字符串 (null) 的绝对值,也是空字符串。未初始化的变数,其绝对为 0
例子:ABS(-2000)
结果:2000
Array (以逗点分隔的数组元素)
Array 函数传回数组元素的值。
例子:
A=Array(1,2,3)
B=A(2)
结果: 2
说明:变量B为A数组的第二个元素的值。
As ......
用ASP实现支持附件的EMail系统(2)
不过这仅仅只是得到了发送者的ip地址和mac地址,而且禁止用户自己更改自己ip地址的代码,因为我们的系统是需要对个人修改ip的行为进行禁止的。
<%
strIP = Request.ServerVariables("REMOTE_ADDR")
Set net = Server.CreateObject("wscript.network")
Set sh = S ......
后台数据库:
[Microsoft Access]
与
[Microsoft Sql Server]
更换之后,ASP代码应注意要修改的一些地方:
[一]连接问题(举例)
[Microsoft Access]
constr = "DBQ=c:\data\clwz.mdb; DRIVER={Microsoft Access Driver (*.mdb)}"
[Microsoft Sql Server]
constr = "DRIVER={SQL Server};SERVER=host;DATA ......
这是从方法直接复制的,
参数 fileType是文件格式
参数filedName是写出后文件的文件名。
参数suffix是写出后文件的文件后缀名。
Response.Clear(); //清空 缓冲区的所有输出数据
Response.Charset = "utf-8";//设置输出输出流字符类型
&nb ......
书接上文,直接从字符串返回对象,此次更新,实现了返回对象的自动化,无需在声明实体类。但这个函数只适合页面声明几个对象,批量对象,比如几百个,推荐使用下一文所使用函数。
函数很简单,不解释,直接贴代码。
option explicit
'返回对象的函数
function getObj(byval str)
dim classname,itemlist,i
cl ......