◆挑战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
。。。
...全文
407 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)
后台/admin 用户名admin密码admin888 时代商城购物系统简介 时代商城购物系统购物系统是一个经过完善设计,适用于各种服务器环境的高效购物系统解决方案。时代网联信息科技有限公司具有丰富的 web 应用程序设计经验,尤其在购物系统产品及相关领域,经过长期创新性开发,掌握了一整套从算法,数据结构到产品安全性方面的领先技术,使得时代商城购物系统无论在稳定性、负载能力、安全保障等方面都居于国内外同类产品领先地位。 时代商城购物系统从创立之初就以提高产品效率、切实降低企业成本、提高企业竞争力为突破口,经过几年对新内核架构的开发与实际测试,我们掌握了大量第一手数据资料和设计经验,率先实现并应用了编译模板、语法生成内核、数据缓存和自动更新机制等独有创新性技术,使得其短期内从众多竞争对手中脱颖而出,实现了前所未有的负载能力。接着,我们成功的发布了最新的高效率国际化内核,使其走出国门,步入海外市场。目前,时代商城购物系统购物已被很多大型企业网站采用,商业客户遍及中国大陆、香港、台湾、北美、欧洲、澳洲和马来西亚等国家和地区。 我们适时地将产品重点转向个性化功能开发和产品安全稳定的针对性研究,考虑实际环境和客户需求使得时代商城购物系统在上述两个方面获得了令人满意的进展。在功能和稳定性大上台阶的同时,我们不忘巩固已有的负载能力优势,,新的版本在产品效率上又获得了突破性进展。时代商城购物系统拥有一支富于创新的开发队伍,持续性的技术优势和不断增长的市场经验,除了强化已有的市场竞争力以外,更增强了已有和潜在客户的信心,我们并不满足于现有成果,我们时刻关注国内外相关领域内的最新进展和动态,不断的进步和创新,已使越来越多的人相信时代商城购物系统辉煌的明天。 如果您正在寻找一个出色的购物系统解决方案,如果原有产品无法适应您企业的不断增长,如果您为不断提升的硬件需求而苦恼,如果您的网站因为服务器的不堪重负而停滞不前,时代商城购物系统将为您提供一个崭新的机遇和选择。 作为商业软件产品,时代商城购物系统在代码优化、运行效率、负载能力、安全等级、功能可操控性和权限严密性等方面都在广大用户中有良好的口碑。凭借时代网联信息科技有限公司长期积累的丰富的web开发及数据库经验和强于创新追求完美的设计理念,使得时代商城购物系统在很短时间内以其鲜明的个性特色从国内外同类产品中脱颖而出。经过了效率最优化和负载能力最佳化设计的时代商城购物系统,已获得业内越来越多专家和权威企业的认可。 卓越的访问速度和负载能力 时代商城购物系统从创立之初即以提高产品效率为突破口,随着编译模板、语法生成内核、数据缓存和自动更新机制等独创和独有技术的应用和坚固的数据结构及最少化数据库查询设计,使得时代商城购物系统可以在极为繁忙的服务器环境下快速稳定运行,切实节约企业成本,提升企业形象。 强大而完善的功能 除了一般商城购物系统有的功能外,时代商城购物系统还提供了很大限度的个性化设定,众多功能在后台预留开关,可按企业需要启用。前台全部采用编译模板技术构建,更换界面易如反掌,完善的权限设定,使管理员可控制到每个用户。 国际化和标准化的产品架构 目前发布的版本分为简体中文和英文两个版本。自时代商城购物系统新版以来,因其高效国际化内核的应用,使其成功走出国门,步入海外市场,商业客户遍及中国大陆、香港、台湾、北美、欧洲、澳洲和马来西亚等国家和地区,英语版暂时不向大陆开放。 周密的安全部署和攻击防护 时代商城购物系统能有效处理页面格式,保证页面及表格的完整性。安全检查应用于每一个时代商城购物系统代码中,独有的全程操作记录,使时代商城购物系统情况随时有据可查。 持久的创新和广阔的前景 时代商城购物系统拥有一支富于创新的开发队伍,持续性的技术优势和不断增长的市场经验,除了强化已有的市场竞争力以外,更增强了已有和潜在客户的信心,我们并不满足于现有成果,我们时刻关注国内外相关领域内的最新进展和动态,不断的进步和创新,已使越来越多的人相信时代商城购物系统辉煌的明天。 算法及数据结构 我们始终致力于开发最优化的算法和数据结构,在从事 ASP 与 MSSQL 的开发的过程中,我们力求每行代码都充分发挥开发工具的效率优势。时代商城购物系统是一个挑战 ASP 应用极限的应用程序。时代商城购物系统开发团队具有丰富的 cache 处理经验,时代商城购物系统内建了包含系统设定到模板系统在内的 ASP 语法生成内核,此内核可直接生成程序格式的缓存,cache 的广泛应用使得时代商城购物系统的代码效率再上新的台阶。 时代商城购物系统中包含了众多独创和独有的处理方法,使得时代商城购物系统可以轻松承受比其他类似产品更多的商品数量和在线人数,成为目前最高效快速的购物系统产品之一。在实现同样功能的前提下,时代商城

28,406

社区成员

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

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