主题:探讨下:如何把让数组里面的字符串连接起来
<%
dim strsql,conn,rs
set conn=server.createobject("adodb.connection")
conn.connectionstring="DRIVER={SQL Server};SERVER=192.168.1.102;uid=sa;pwd=sa;DATABASE=goto63net"
set rs=server.createobject("adodb.recordset")
conn.open
rs.open"select top 9 topic_title,postdate from bbs_topics",conn,1,1
'这里打开出一个表取出9条纪录来
'------方法一------------------------------------
'这里设置strTemp1,strTemp2,strTemp3把数据保存起来
dim strTemp1,strTemp2,strTemp3
dim i :i=1 '声明设置变量值
strTemp1=""
strTemp2=""
strTemp3=""
while not rs.eof
if i<=3 then '字符串连接肯定是最费时的了
strTemp1=strTemp1&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
elseif i<=6 then
strTemp2=strTemp2&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
elseif i<=9 then
strTemp3=strTemp3&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
end if
i=i+1
rs.movenext
wend
'-------方法二-------------------------------------------------------
rs.MoveFirst() '回到首行
dim strTemp(9) '设置一个9的数组
i=0
while not rs.eof
strTemp(i)="<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
i=i+1
rs.movenext
wend
'那我在怎么把3一组连接成字符串 然后直接在下面调用就好拉
dim strTemp4:strTemp4=""
dim strTemp5:strTmep5=""
dim strTemp6:strTmep6=""
'strTemp4=strTemp(0)&strTemp(2)&strTemp(2)
'我自己想是这么做,但和上面的方法一的连接字符串一样了,有什么好的方法啊
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
<table style="font-size:12px;" width="50%" align="center" height="100" border="1" cellspacing="0" cellpadding="0">
<tr><td colspan="3" style="font-size:16px;font-weight:800;color:#0033CC;">这是方法一显示结果:</td></tr>
<tr>
<td><%=strTemp1%></td>
<td><%=strTemp2%></td>
<td><%=strTemp3%></td>
</tr>
</table>
<table style="font-size:12px;" width="50%" align="center" height="100" border="1" cellspacing="0" cellpadding="0">
<tr><td colspan="3" style="font-size:16px;font-weight:800;color:#0033CC;">这是方法二显示结果:</td></tr>
<tr>
<td><%=strTemp4%></td>
<td><%=strTemp5%></td>
<td><%=strTemp6%></td>
</tr>
</table>
关键是这句:
'strTemp4=strTemp(0)&strTemp(2)&strTemp(2)
'我自己想是这么做,但和上面的方法一的连接字符串一样了,有什么好的方法啊
怎么连接才能减少字符串连接的开销呢。
dim strsql,conn,rs
set conn=server.createobject("adodb.connection")
conn.connectionstring="DRIVER={SQL Server};SERVER=192.168.1.102;uid=sa;pwd=sa;DATABASE=goto63net"
set rs=server.createobject("adodb.recordset")
conn.open
rs.open"select top 9 topic_title,postdate from bbs_topics",conn,1,1
'这里打开出一个表取出9条纪录来
'------方法一------------------------------------
'这里设置strTemp1,strTemp2,strTemp3把数据保存起来
dim strTemp1,strTemp2,strTemp3
dim i :i=1 '声明设置变量值
strTemp1=""
strTemp2=""
strTemp3=""
while not rs.eof
if i<=3 then '字符串连接肯定是最费时的了
strTemp1=strTemp1&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
elseif i<=6 then
strTemp2=strTemp2&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
elseif i<=9 then
strTemp3=strTemp3&"<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
end if
i=i+1
rs.movenext
wend
'-------方法二-------------------------------------------------------
rs.MoveFirst() '回到首行
dim strTemp(9) '设置一个9的数组
i=0
while not rs.eof
strTemp(i)="<P>"&rs("topic_title")&"--"&rs("postdate")&"</p>"
i=i+1
rs.movenext
wend
'那我在怎么把3一组连接成字符串 然后直接在下面调用就好拉
dim strTemp4:strTemp4=""
dim strTemp5:strTmep5=""
dim strTemp6:strTmep6=""
'strTemp4=strTemp(0)&strTemp(2)&strTemp(2)
'我自己想是这么做,但和上面的方法一的连接字符串一样了,有什么好的方法啊
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
<table style="font-size:12px;" width="50%" align="center" height="100" border="1" cellspacing="0" cellpadding="0">
<tr><td colspan="3" style="font-size:16px;font-weight:800;color:#0033CC;">这是方法一显示结果:</td></tr>
<tr>
<td><%=strTemp1%></td>
<td><%=strTemp2%></td>
<td><%=strTemp3%></td>
</tr>
</table>
<table style="font-size:12px;" width="50%" align="center" height="100" border="1" cellspacing="0" cellpadding="0">
<tr><td colspan="3" style="font-size:16px;font-weight:800;color:#0033CC;">这是方法二显示结果:</td></tr>
<tr>
<td><%=strTemp4%></td>
<td><%=strTemp5%></td>
<td><%=strTemp6%></td>
</tr>
</table>
关键是这句:
'strTemp4=strTemp(0)&strTemp(2)&strTemp(2)
'我自己想是这么做,但和上面的方法一的连接字符串一样了,有什么好的方法啊
怎么连接才能减少字符串连接的开销呢。