◆挑战ASP极限算法二

huaerinfo 2006-01-05 09:21:58
假如数据库有以下内容:
id explace
1 aa1=001;002;003;004;005;006;007;008;b2=001;002;003;004;005;006;007;008;....
(还有未知的)

我现在需要把explace读出来,并显示如下成如下的三列的表格方式:

aa1
001 002 003
004 005 006
007 008
b2
001 002 003
004 005 006
007 008
。。。
...全文
412 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjjf 2006-01-05
  • 打赏
  • 举报
回复
正则表达式处理这个很简单的,有空的话帮你看看
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
*********************************
以下就是完整的程序,newexplain就是显示不出,晕了。。
<!--#include file="conn.asp" -->

<%'处理上述的问题,生成需要的格式
function outtable(byval content)
temp=0
htmlcode= "<table>"
content1=split(content,";")
for i=0 to ubound(content1)
templen=instr(content1(i),"=")
if templen>0 then
htmlcode=htmlcode & "</tr><tr><td colspan=3>"&left(content1(i),templen-1)&"</td></tr><tr>"
content1(i)=mid(content1(i),templen+1)
temp=i
else
if (i-temp) mod 3 =0 then htmlcode=htmlcode & "</tr><tr>"
end if
htmlcode=htmlcode & "<td>" & content1(i) & "</td>"
next
if (i-temp-1) mod 3 <> 0 then
for j=1 to i-1
htmlcode=htmlcode & "<td></td>"
next
end if
htmlcode=htmlcode & "</tr>"
htmlcode=htmlcode & "</table>"
'return htmlcode
content=htmlcode
end function
%>


<%
set rs=server.createobject("adodb.recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
sqla="select * from product where id=466 "
rs.open sqla,conn,1,1


set test=server.createobject("adodb.recordset")'打开数据库中的模板文件,用于生成HTML
modesql="select * from mode where id=1"
test.open modesql,conn,1,1
modehtml=test("modehtml")
test.close

newname=rs("name")
newexplain="a=001;002;003;004;b=001;002"
newexplain=outtable(newexplain)


modehtml=replace(modehtml,"newexplain",newexplain)'打开模板中需要替换的位置,进行替换



NewFile=Server.MapPath("html/"&newname&".html") '以下是用于生成html文件
Set nf = fso.CreateTextFile(NewFile, True)
nf.close
File=Server.MapPath("ht/"&newname&".html")
Set txt=fso.OpenTextFile(File,8,True)
txt.Write modehtml
txt.Close
response.write "<script>alert('HTML导出成功!');</script>"
rs.close
set fso=nothing
conn.close
%>
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
我换了,但还是不行。。你分析下。
<!--#include file="conn.asp" -->

<%
function htmlcode(byval content)
temp=0
htmlcode= "<table>"
content1=split(content,";")
for i=0 to ubound(content1)
templen=instr(content1(i),"=")
if templen>0 then
htmlcode=htmlcode & "</tr><tr><td colspan=3>"&left(content1(i),templen-1)&"</td></tr><tr>"
content1(i)=mid(content1(i),templen+1)
temp=i
else
if (i-temp) mod 3 =0 then htmlcode=htmlcode & "</tr><tr>"
end if
htmlcode=htmlcode & "<td>" & content1(i) & "</td>"
next
if (i-temp-1) mod 3 <> 0 then
for j=1 to i-1
htmlcode=htmlcode & "<td></td>"
next
end if
htmlcode=htmlcode & "</tr>"
htmlcode=htmlcode & "</table>"
outtable=htmlcode
end function
%>


<%
set rs=server.createobject("adodb.recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
sqla="select * from product where id=466 "
rs.open sqla,conn,1,1


set test=server.createobject("adodb.recordset")'打开数据库中的模板文件,用于生成HTML
modesql="select * from mode where id=1"
test.open modesql,conn,1,1
modehtml=test("modehtml")
test.close

newname=rs("name")
newexplain=htmlcode(newexplain)
'outtable=htmlcode

modehtml=replace(modehtml,"newexplain",newexplain)'打开模板中需要替换的位置,进行替换


modehtml=replace(modehtml,"newsmallimg",newsmallimg)
modehtml=replace(modehtml,"newbigimg",newbigimg)




NewFile=Server.MapPath("html/"&newname&".html") '以下是用于生成html文件
Set nf = fso.CreateTextFile(NewFile, True)
nf.close
File=Server.MapPath("ht/"&newname&".html")
Set txt=fso.OpenTextFile(File,8,True)
txt.Write modehtml
txt.Close
response.write "<script>alert('HTML导出成功!');</script>"
rs.close
set fso=nothing
conn.close
%>
邦迪代驾 2006-01-05
  • 打赏
  • 举报
回复
学习
hebhd 2006-01-05
  • 打赏
  • 举报
回复
response.write "<textarea cols=40 rows=6>"&htmlcode&"</textarea>"
response.write htmlcode
换成 outtable=htmlcode
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
汉德,谢谢。
是改在那个位置?
我改了,现在提示:
类型错误
hebhd 2006-01-05
  • 打赏
  • 举报
回复
newexplain=outtable(newexplain)
用我给你的代码将里面改一句

outtable=htmlcode
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
xhbmj, hebhd谢谢你们。
还有最后一问:是关于以上处理结果的应用,但是却显示不出来了???
究竞是那个地方出问题了??

<!--#include file="conn.asp" -->

<%
function outtable(byval content) '用于处理输出的格式,就是上面所提的问题

content1 = Split(content,"=")
For j=0 to Ubound(content1)-1
a=split(content1(j),";")(UBound(split(content1(j),";")))
response.write("<TR><TD colspan=3>")
response.write(a)
response.write("</TD></TR>")

response.write("<tr>")

'on error resume next
content2 = Split(content1(j+1),";")
For i=0 to UBound(content2)-1
If i Mod 3=0 Then Response.write("<tr>")
response.write("<TD width=100>")
response.write(content2(i))
response.write("</TD>")
Next
response.write("</TR>")
Next
end function
%>

<%
set rs=server.createobject("adodb.recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
sqla="select * from product where id=466 "
rs.open sqla,conn,1,1


set test=server.createobject("adodb.recordset")'打开数据库中的模板文件,用于生成HTML
modesql="select * from mode where id=1"
test.open modesql,conn,1,1
modehtml=test("modehtml")
test.close


newexplain=rs("explain")
newexplain=outtable(newexplain)
modehtml=replace(modehtml,"newexplain",newexplain)'打开模板中需要替换的位置,进行替换


modehtml=replace(modehtml,"newsmallimg",newsmallimg)
modehtml=replace(modehtml,"newbigimg",newbigimg)




NewFile=Server.MapPath("html/"&newname&".html") '以下是用于生成html文件
Set nf = fso.CreateTextFile(NewFile, True)
nf.close
File=Server.MapPath("html/"&newname&".html")
Set txt=fso.OpenTextFile(File,8,True)
txt.Write modehtml
txt.Close
response.write "<script>alert('HTML导出成功!');</script>"
rs.close
set fso=nothing
conn.close
%>

lstup 2006-01-05
  • 打赏
  • 举报
回复
问问题就老实点,别搞这些什么花头。
用split分离出来简单得很
hebhd 2006-01-05
  • 打赏
  • 举报
回复
To:huaerinfo(三楼一人)
如果你自已都看不出来数据的规率的话.没有任何人可以帮你忙的

你必须要能找出他们的规律性.

或者你将数据库的部分数据给大家公示一下.

最好你能将原数据库的结构算法找出来..
hebhd 2006-01-05
  • 打赏
  • 举报
回复
<%
function outtable(byval content)
temp=0
htmlcode= "<table>"
content1=split(content,";")
for i=0 to ubound(content1)
templen=instr(content1(i),"=")
if templen>0 then
htmlcode=htmlcode & "</tr><tr><td colspan=3>"&left(content1(i),templen-1)&"</td></tr><tr>"
content1(i)=mid(content1(i),templen+1)
temp=i
else
if (i-temp) mod 3 =0 then htmlcode=htmlcode & "</tr><tr>"
end if
htmlcode=htmlcode & "<td>" & content1(i) & "</td>"
next
if (i-temp-1) mod 3 <> 0 then
for j=1 to i-1
htmlcode=htmlcode & "<td></td>"
next
end if
htmlcode=htmlcode & "</tr>"
htmlcode=htmlcode & "</table>"
response.write "<textarea cols=40 rows=6>"&htmlcode&"</textarea>"
response.write htmlcode
end function
%>

<%
content3="abc=001;002;003;004;005;006;007;009;b=001;002;003;004;005;006;007;008;c=001;002;003;004;005;006;007;008;d=001;002;003;004;005;006;007;008;"
ccc=outtable(content3)
%>
无爱大叔 2006-01-05
  • 打赏
  • 举报
回复
<%
function outtable(byval content)

content1 = Split(content,"=")
For j=0 to Ubound(content1)-1
a=split(content1(j),";")(UBound(split(content1(j),";")))
response.write("<TR>")
response.write("<TD colspan=3>")
response.write(a)
response.write("</TD></TR>")
response.write("<tr>")
'on error resume next
content2 = Split(content1(j+1),";")
For i=0 to UBound(content2)-1
If i Mod 3=0 Then Response.write("<tr>")
response.write("<TD width=100>")
response.write(content2(i))
response.write("</TD>")
Next
response.write("</TR>")
Next
end function
%>

<table>
<%
content3="abc=001;002;003;004;005;006;007;009;b=001;002;003;004;005;006;007;008;c=001;002;003;004;005;006;007;008;d=001;002;003;004;005;006;007;008;"
ccc=outtable(content3)
%>
</table>
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
id explace
1 =aa1;001;002;003;004;005;006;007;008;=b2;001;002;003;004;005;006;007;008;....
(还有未知的)

我也可以更改成这样的结构,反正主要能把aa1,b2区分出来,并把所属的内容读出来就行了。
在线等待中。。
jspadmin 2006-01-05
  • 打赏
  • 举报
回复
晕了,重复问题
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
大家都去那了。。
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
不是拉,又发现问题了,你帮一下好不?
我搞不定啊。
KimSoft 2006-01-05
  • 打赏
  • 举报
回复
晕,楼主又来啦,散分啊。我接。
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
晕,这还简单,那位高手能帮我修改下啊。。
虚拟过客 2006-01-05
  • 打赏
  • 举报
回复
简单,就是字符串操作而已
huaerinfo 2006-01-05
  • 打赏
  • 举报
回复
Javascript版本的
=====================================================

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
<script language="javascript">
var TempStr = "a=001;002;003;004;005;006;007;008;b=001;002;003;004;005;006;007;008;";
var ArrayStr = TempStr.split("=");
for(i=0;i<ArrayStr.length;i++)
{
//输出a
if(ArrayStr[i].indexOf(";") < 0)
{
document.write(ArrayStr[i]+"<br/>");
}
else //输出其他部分
{
if(ArrayStr[i].indexOf("b") >= 0) //输出a中数值及b
{
ArrayStr[i] = ArrayStr[i].replace("b","");
var ArraySubStr = ArrayStr[i].split(";");
var counter = 0;
for(j=0;j<ArraySubStr.length;j++)
{
document.write(ArraySubStr[j]+" ");
counter++;
if(counter%3==0)
{
document.write("<br/>");
}
}
document.write("b<br/>");
}
else //输出b中数值
{
var ArraySubStr = ArrayStr[i].split(";");
var counter = 0;
for(j=0;j<ArraySubStr.length;j++)
{
document.write(ArraySubStr[j]+" ");
counter++;
if(counter%3==0)
{
document.write("<br/>");
}
}
}
}
}
</script>
</head>
<body>
</body>
</html>
这是大花狗给的,但也有个问题就是只能算出a与b两个,如果超过了三个就算不出了。
加载更多回复(6)

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧