asp画中画广告插入在每篇文章中的实现方法(画中画广告图片)一看就会

随心笔谈3年前发布 admin
213 0 0

文章摘要

这篇文章介绍了两个Visual Basic函数的实现及其用途。第一个函数`Function InterceptString(txt,length)`用于截取字符串并进行相关判断。该函数首先对输入字符串进行处理,判断字符类型(中文或ASCII),并对长度超过定义子字符串长度的情况进行处理,同时判断是否包含敏感字符串。第二个函数`Function StrCount(Str,SubStr)`用于统计目标字符串中特定子字符串的出现次数。该函数通过循环查找子字符串并统计次数。两段代码均涉及字符串处理逻辑,关键词密度在2%左右。


Function InterceptString(txt,length)
Dim x,y,ii,c,ischines,isascii,tempStr
txt=trim(txt)
x=len(txt)
y=0
if x >=1 then
for ii=1 to x
c=asc(mid(txt,ii,1))
if c< 0 or c >255 then
‘说明是一个中文字符
y=y + 2
ischines=1
isascii=0
else
‘说明是一个ascii码
y=y + 1
ischines=0
isascii=1
end if
‘如果长度已经大于定义子字符串长度,就判断是否包含敏感字符串是否分开
if y >=length then
if ischines=1 and StrCount(left(trim(txt),ii),”<a”)=StrCount(left(trim(txt),ii),”</a>”) then
txt=left(trim(txt),ii) ‘”字符串限长
exit for
else
if isascii=1 then x=x+1
end if
end if
next
InterceptString=txt
else
InterceptString=””
end if
End Function
‘判断字符串出现的次数
Function StrCount(Str,SubStr)
Dim iStrCount
Dim iStrStart
Dim iTemp
iStrCount=0
iStrStart=1
iTemp=0
Str=LCase(Str)
SubStr=LCase(SubStr)
Do While iStrStart < Len(Str)
iTemp=Instr(iStrStart,Str,SubStr,vbTextCompare)
If iTemp <=0 Then
iStrStart=Len(Str)
Else
iStrStart=iTemp + Len(SubStr)

iStrCount=iStrCount + 1
End If
Loop
StrCount=iStrCount
End Function

© 版权声明

相关文章