当前位置:编程学习 > asp >>

ASP常见问题及解答(7)

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
补充:asp教程,技巧与性能优化
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,