帮忙解释这段代码ASP

来源:百度知道 编辑:UC知道 时间:2024/06/27 14:42:58
帮忙详细解释下面这段代码,看不懂
还有,我知道split是分割函数,这么用有什么好处?
table_fields=split(trim(table_field),",")
用 ,来分什么? 怎么分?

function keyword_sousuo(byval table_field,byval keyword)
dim str01,str02,keywords,table_fields,i,j

table_fields=split(trim(table_field),",")
keywords=split(trim(keyword),",")

if table_field<>"" then
str01="("&table_fields(0)&" like '%"&keyword&"%'"
for j=0 to ubound(table_fields)
str01=str01&" or "&table_fields(j)&" like '%"&keyword&"%'"
next
str01=str01&")"
else
response.Write("<script>alert('参数错误(不能为空)!')</script>")
response.End()
end if
解释下这段代码。。追加50分

<%
function keyword_sousuo(byval table_field,byval keyword)
'定义一个keyword_sousuo方法有两个参数
dim str01,str02,keywords,table_fields,i,j
'声明及将要使用的变量
table_fields=split(trim(table_field),",")
'把参数table_field按逗号进行分割,返回一个table_fields数组
keywords=split(trim(keyword),",")
'把参数keyword按逗号进行分割,返回一个keywords数组
'+++++++++++++++++++++++++++++++++++++++++++++++++++
'分割数组的好处是。可以单个访问其中某一个字符。
'比如一个字符串是a="a,b,c,d,e,f,g"如果你要访问其中单个字符,
'那就使用b=split(a,",")进行分割。得到一个新数组使用下标b(0)的值就是a.依次类推
'+++++++++++++++++++++++++++++++++++++++++++++++++++
if table_field<>"" then
'如果这个参数不为空
str01="("&table_fields(0)&" like '%"&keyword&"%'"
'哪么分割到的数组就会有值.这里是构造一个sql模糊查找语句。

for j=0 to ubound(table_fields)
str01=str01&" or "&table_fields(j)&" like '%"&keyword&"