Function CheckTheChar(TheChar,TheString)
'TheChar="要檢測(cè)的字符串"
'TheString="待檢測(cè)的字符串"
if inStr(TheString,TheChar) then
for n =1 to Len(TheString)
if Mid(TheString,n,Len(TheChar))=TheChar then
CheckTheChar=CheckTheChar+1
End if
Next
CheckTheChar="這個(gè)字符"&CheckTheChar&"次"
else
CheckTheChar="0次"
end if
End Function
example:
程序代碼
Response.Write CheckTheChar("大家","a224大家4a434a4大家654arewr4a4a")
程序代碼
<%
'檢測(cè)字符串Str1在字符串Str2中出現(xiàn)的次數(shù)
Public Function SearchChar(Str1, Str2)
Dim I, Counter
Counter = 0
If InStr(Str2, Str1) Then
For I = 1 To Len(Str2)
If Mid(Str2, I, Len(Str1))=Str1 Then
Counter = Counter + 1
End If
Next
End if
SearchChar = Counter
End Function
%>
<form name="form1" method="post" action="">
<p> 輸入兩個(gè)字符串:</p>
<p> 字符串1:
<input name="text1" type="text" id="text">
</p>
<p> 字符串2:
<input name="text2" type="text" id="text">
<input type="submit" name="Submit" value="提交">
</p>
</form>
<%
Dim X,Y
X=Request.Form("text1")
Y=Request.Form("text2")
If X<>"" and Y<>"" Then
%>
<p>字符串1:<%=X%></p>
<p>字符串2:<%=Y%></p>
<p>字符串1在字符串2中出現(xiàn)的次數(shù)<%=SearchChar(X,Y)%></p>
<%
End If
%>
簡(jiǎn)單改造之后就可以變成一個(gè)檢測(cè)當(dāng)留言內(nèi)容中url超過(guò)2個(gè),則屏蔽之類的函數(shù)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注