电脑技术学习

做程序经常有html与asp的代码互换

dn001

<!-- 把如下代码加入<body>区域中 -->
<SCRIPT language=vbscript>
<!--
function autocr()
if checkbox.checked then
html.wrap="soft"
asp.wrap="soft"
else
html.wrap="off"
asp.wrap ="off"
end if
end function

function HtmlToAsp(str)
dim i,AspStr,tmp,st
AspStr=""
for i=1 to Len (str)
tmp=Mid(str,i,1)
select case tmp
case """"
if not st then;tmp=""""""
case "<"
if Mid(str,i+1,1)="%" then
tmp="""&"
if mid(str,i+2,1)="=" then i=i+2 else i=i+1
st=true
end if
case "%"
if Mid(str,i+1,1)=">" then
tmp="&"""
st=false
i=i+1
end if
end select
AspStr=AspStr&tmp
next
HtmlToAsp="Response.Write """&AspStr&"""&VbCrLf"
end function

function AspToHtml(str)
dim i,HtmStr,tmp,itmp,st
str=Trim(str)
HtmStr=""
st=3
if strcomp(mid(str,1,14),"Response.Write",1)=0 then str=LTrim(mid(str,15))
for i=1 to Len(str)
tmp=Mid (str,i,1)
if tmp="""" then
if mid(str,i+1,1)="""" and st=1 then
tmp=""""
i=i+1
elseif mid(str,i+1,1)="&" and st=1 then
st=0
if mid(str,i+2,1)="""" then
tmp=""
st=1
i=i+2
elseif strcomp(mid(str,i+2,6),"VbCrLf",1)=0 then
if i+7=len(str) then tmp="" else tmp=VbCrLf
i=i+7
else
tmp="<%"
i=i+1
end if
elseif st=3 then
tmp=""
st=1
elseif i=len(str) and st=1 then
tmp=""
st=0
end if
elseif tmp="&" and mid(str,i+1,1)="""" and st=0 then
st=1
tmp="%>"
i=i+1
end if
HtmStr=HtmStr&tmp
next
AspToHtml=HtmStr
end function

function hta()
dim ahtm,aspstr,inum
if html.value>"" then
ahtm=Split (html.value ,vbCrLf,-1,0)
inum=UBound(ahtm)
for i=0 to inum
aspstr=aspstr&HtmlToAsp (ahtm(i))
if i<inum-1 then aspstr=aspstr&vbCrLf
next
asp.value =aspstr
end if
end function

function ath()
dim aasp,htmstr,inum
if asp.value>"" then
aasp=Split (asp.value ,vbCrLf,-1,0)
inum=UBound (aasp)
for i=0 to inum
htmstr=htmstr&AspToHtml (aasp(i))
if i<inum-1 then htmstr =htmstr &vbCrLf
next
html.value =htmstr
end if
end function

function selall(obj)
obj.select
end function
-->
</SCRIPT>
<TABLE id=AutoNumber1 style="BORDER-COLLAPSE: collapse" borderColor=#111111
cellSpacing=0 cellPadding=5 width="100%" border=0>
<TBODY>
<TR>
<TD width="100%" colSpan=3><TEXTAREA class=myinput onfocus=selall(html) name=html rows=10 wrap=off cols=102></TEXTAREA>
</TD></TR>
<TR>
<TD width="40%">
<P align=right><INPUT class=mybutton style="WIDTH: 150px; HEIGHT: 25px" onclick=hta type=button value=HTML转ASP name=toasp>
</P></TD>
<TD width="16%">  <INPUT onclick=autocr type=checkbox value=checkbox
name=checkbox> 自动换行</TD>
<TD width="44%"><INPUT class=mybutton style="WIDTH: 150px; HEIGHT: 25px" onclick=ath type=button value=ASP转HTML name=tohtml>
</TD></TR>
<TR>
<TD width="100%" colSpan=3><TEXTAREA class=myinput onfocus=selall(asp) name=asp rows=10 wrap=off cols=102></TEXTAREA>
</TD></TR>
<TR align=middle>
<TD width="100%" colSpan=3></TD></TR></TBODY></TABLE>