分享
 
 
 

ASP精华问题7

王朝asp·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

1.分 类:语法应用

问题描述:查找两个字符串间的字符出现次数

解决办法:

function FindStringTimes(strContent,start_string,end_string) 'start_string 与 end_string 之间字符出次的数

'written by Jaron

FindStringTimes = ubound(split(strContent,start_string))

end function

示例: 查找以下字符串有多少张图片

response.write FindStringTimes(HTML,"<img",">")

<img src="a.jpg"><img src="b.jpg"><img src="d.jpg"><img src="c.jpg">

2.遍历目录以及目录下文件的函数

<%

function bianli(path)

set fso=server.CreateObject("scripting.filesystemobject")

on error resume next

set objFolder=fso.GetFolder(path)

set objSubFolders=objFolder.Subfolders

for each objSubFolder in objSubFolders

nowpath=path + "\" + objSubFolder.name

Response.Write nowpath

set objFiles=objSubFolder.Files

for each objFile in objFiles

Response.Write "<br/>---"

Response.Write objFile.name

next

Response.Write "<p>"

bianli(nowpath)'递归

next

set objFolder=nothing

set objSubFolders=nothing

set fso=nothing

end function

%>

<%

bianli("d:") '遍历d:盘

%>

3.生成一个不重复的随即数字

Sub CalCaPiao()

Dim strCaiPiaoNoArr() As String

Dim strSQL As String

Dim strCaiPiaoNo As String

strCaiPiaoNo = "01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33"

Dim StrTempArr(7) As String

Dim strZhongJiangArr(7) As String

strCaiPiaoNoArr = Split(strCaiPiaoNo, ",")

Dim intRand As Integer

Dim i As Integer

Dim j As Integer

i = 0

Dim find As Boolean

Do While True

find = False

Randomize

intRand = Int((33 * Rnd) + 1)

For j = 0 To i - 1

If StrTempArr(j) = CStr(intRand) Then

find = True

End If

Next

If Not find Then

StrTempArr(j) = CStr(intRand)

strZhongJiangArr(i) = CStr(intRand)

'Text1(i) = strZhongJiangArr(i)

i = i + 1

If i = 7 Then

Exit Do

End If

End If

Loop

End Sub

4.下载任何文件(尤其是IE关联打开的)

<%

Dim Stream

Dim Contents

Dim FileName

Dim FileExt

Const adTypeBinary = 1

FileName = Request.QueryString("FileName")

if FileName = "" Then

Response.Write "无效文件名."

Response.End

End if

' 下面是不希望下载的文件

FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)

Select Case UCase(FileExt)

Case "ASP", "ASA", "ASPX", "ASAX", "MDB"

Response.Write "受保护文件,不能下载."

Response.End

End Select

' 下载这个文件

Response.Clear

Response.ContentType = "application/octet-stream"

Response.AddHeader "content-disposition", "attachment; filename=" & FileName

Set Stream = server.CreateObject("ADODB.Stream")

Stream.Type = adTypeBinary

Stream.Open

Stream.LoadFromFile Server.MapPath(FileName)

While Not Stream.EOS

Response.BinaryWrite Stream.Read(1024 * 64)

Wend

Stream.Close

Set Stream = Nothing

Response.Flush

Response.End

%>

5.背景色变换

<form>

<p><input TYPE="button" value="背景色变换" onClick="BgButton()"></p>

</form>

<script>function BgButton(){

if (document.bgColor==#00ffff)

{document.bgColor=#ffffff;}

else{document.bgColor=#00ffff;}

}

</script>

6.点击打开新窗口

<form>

<p><input TYPE="button" value="打开新窗口" onCLICK="NewWindow()"></p>

</form>

<script language="javascript"><!--

function NewWindow(){window.open("http://www.mcmx.com";;;;,"","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}

// --></script></body>

||||||7.分页代码:

<%本程序文件名为:Pages.asp%>

<%包含ADO常量表文件adovbs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%>

<!--#Include File="adovbs.inc"-->

<%*建立数据库连接,这里是Oracle8.05数据库

Set conn=Server.CreateObject("ADODB.Connection")

conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;"

Set rs=Server.CreateObject("ADODB.Recordset") 创建Recordset对象

rs.CursorLocation=adUseClient 设定记录集指针属性

*设定一页内的记录总数,可根据需要进行调整

rs.PageSize=10

*设置查询语句

StrSQL="Select ID,姓名,住址,电话 from 通讯录 Order By ID"

rs.Open StrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText

%>

<HTML>

<HEAD>

<title>分页示例</title>

<script language=javascript>

//点击"[第一页]"时响应:

function PageFirst()

{

document.MyForm.CurrentPage.selectedIndex=0;

document.MyForm.CurrentPage.onchange();

}

//点击"[上一页]"时响应:

function PagePrior()

{

document.MyForm.CurrentPage.selectedIndex--;

document.MyForm.CurrentPage.onchange();

}

//点击"[下一页]"时响应:

function PageNext()

{

document.MyForm.CurrentPage.selectedIndex++;

document.MyForm.CurrentPage.onchange();

}

//点击"[最后一页]"时响应:

function PageLast()

{

document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;

document.MyForm.CurrentPage.onchange();

}

//选择"第?页"时响应:

function PageCurrent()

{ //Pages.asp是本程序的文件名

document.MyForm.action=Pages.asp?Page=+(document.MyForm.CurrentPage.selectedIndex+1)

document.MyForm.submit();

}

</Script>

</HEAD>

<BODY bgcolor="#ffffcc" link="#008000" vlink="#008000" alink="#FF0000"">

<%IF rs.Eof THEN

Response.Write("<font size=2 color=#000080>[数据库中没有记录!]</font>")

ELSE

指定当前页码

If Request("CurrentPage")="" Then

rs.AbsolutePage=1

Else

rs.AbsolutePage=CLng(Request("CurrentPage"))

End If

创建表单MyForm,方法为Get

Response.Write("<form method=Get name=MyForm>")

Response.Write("<p align=center><font size=2 color=#008000>")

设置翻页超链接

if rs.PageCount=1 then

Response.Write("[第一页] [上一页] [下一页] [最后一页] ")

else

if rs.AbsolutePage=1 then

Response.Write("[第一页] [上一页] ")

Response.Write("[<a href=java script:PageNext()>下一页</a>] ")

Response.Write("[<a href=java script:PageLast()>最后一页</a>] ")

else

if rs.AbsolutePage=rs.PageCount then

Response.Write("[<a href=java script:PageFirst()>第一页</a>] ")

Response.Write("[<a href=java script:PagePrior()>上一页</a>] ")

Response.Write("[下一页] [最后一页] ")

else

Response.Write("[<a href=java script:PageFirst()>第一页</a>] ")

Response.Write("[<a href=java script:PagePrior()>上一页</a>] ")

Response.Write("[<a href=java script:PageNext()>下一页</a>] ")

Response.Write("[<a href=java script:PageLast()>最后一页</a>] ")

end if

end if

end if

创建下拉列表框,用于选择浏览页码

Response.Write("第<select size=1 name=CurrentPage onchange=PageCurrent()>")

For i=1 to rs.PageCount

if rs.AbsolutePage=i then

Response.Write("<option selected>"&i&"</option>") 当前页码

else

Response.Write("<option>"&i&"</option>")

end if

Next

Response.Write("</select>页/共"&rs.PageCount&"页 共"&rs.RecordCount&"条记录</font><p>")

Response.Write("</form>")

创建表格,用于显示

Response.Write("<table align=center cellspacing=1 cellpadding=1 border=1")

Response.Write(" bordercolor=#99CCFF bordercolordark=#b0e0e6 bordercolorlight=#000066>")

Response.Write("<tr bgcolor=#ccccff bordercolor=#000066>")

Set Columns=rs.Fields

显示表头

For i=0 to Columns.Count-1

Response.Write("<td align=center width=200 height=13>")

Response.Write("<font size=2><b>"&Columns(i).name&"</b></font></td>")

Next

Response.Write("</tr>")

显示内容

For i=1 to rs.PageSize

Response.Write("<tr bgcolor=#99ccff bordercolor=#000066>")

For j=0 to Columns.Count-1

Response.Write("<td><font size=2>"&Columns(j)&"</font></td>")

Next

Response.Write("</tr>")

rs.movenext

if rs.EOF then exit for

Next

Response.Write("</table>")

END IF

%>

</BODY>

</HTML>

8./**

IsInteger: 用于判断一个数字型字符串是否为整形,

还可判断是否是正整数或负整数,返回值为true或false

string: 需要判断的字符串

sign: 若要判断是正负数是使用,是正用'+',负'-',不用则表示不作判断

Author: PPDJ

sample:

var a = '123';

if (IsInteger(a))

{

alert('a is a integer');

}

if (IsInteger(a,'+'))

{

alert(a is a positive integer);

}

if (IsInteger(a,'-'))

{

alert('a is a negative integer');

}

*/

function IsInteger(string ,sign)

{

var integer;

if ((sign!=null) && (sign!='-') && (sign!='+'))

{

alert('IsInter(string,sign)的参数出错:

sign为null或"-"或"+"');

return false;

}

integer = parseInt(string);

if (isNaN(integer))

{

return false;

}

else if (integer.toString().length==string.length)

{

if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0))

{

return true;

}

else

return false;

}

else

return false;

}

||||||9./**

IsDate: 用于判断一个字符串是否是日期格式的字符串

返回值:

true或false

参数:

DateString: 需要判断的字符串

Dilimeter : 日期的分隔符,缺省值为'-'

Author: PPDJ

sample:

var date = '1999-1-2';

if (IsDate(date))

{

alert('You see, the default separator is "-");

}

date = '1999/1/2";

if (IsDate(date,'/'))

{

alert('The date\'s separator is "/");

}

*/

function IsDate(DateString , Dilimeter)

{

if (DateString==null) return false;

if (Dilimeter=='' || Dilimeter==null)

Dilimeter = '-';

var tempy='';

var tempm='';

var tempd='';

var tempArray;

if (DateString.length<8 &

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有