标题:随机重复 求解~~~
取消只看楼主
sunfeiyao
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2011-9-7
结帖率:12.5%
 问题点数:0 回复次数:0 
随机重复 求解~~~
程序代码:
<%
function FormatReArray(str)
dim temp,sindex,temp1
temp=str&","
temp1=split(temp,",")
for sindex=0 to ubound(temp1)
  if temp1(sindex)<>"" then
  temp=replace(temp,temp1(sindex)&",","")
  temp=temp&temp1(sindex)&","
  end if
next
FormatReArray=left(temp,len(temp)-1)
end function
Function ReplaceReg(str,patrn,replStr,Ignor)
'=========================================
'参数解析:
'str 原来的字符串
'patrn 要替换的字符串(正则表达式)
'replStr 要替换成的字符串
'Ignor 是否区分大小写(1不区分,0区分)
'=========================================
  Dim regEx ' 建立变量。
  If Ignor=1 Then Ignor=true else Ignor=false
  Set regEx = New RegExp ' 建立正则表达式。
  regEx.Pattern = "("&patrn&")" ' 设置模式。
  regEx.IgnoreCase = Ignor ' 设置是否区分大小写。
  regEx.Global=True
  ReplaceReg = regEx.Replace(str,replStr) ' 作替换。
End Function
Function HiddenKeyword(Content,RndKeyWordCount,AllKeyword)
'********************************************
'作者:飞飞
'QQ:276230416
'网址:[url]www.ffasp编程.com
'邮箱:huanmie913@
'********************************************
'函数使用参数说明
'Content: 需要执行添加看不见关键字的字词、段落、字词作品
'RndKeyWordCount: 添加看不见关键字的个数
'AllKeyword: 要添加到字词作品中的字词【要向段落末尾添加的关键字,多关键字请使用"|"分割】


'HiddenColor: 要添加到字词作品中的字词的颜色(和背景色相同,达到看不见的目的)
'*********************************************
'使用的外部函数有 
'1.ReplaceReg [正则表达式替换关键字]
'2.FormatReArray [去除数组中的重复项]
'*********************************************
'使用实例:
'Response.Write(HiddenKeyword("aaaaaaaaaaaa<br />bbbbbbbbbbb<br>ccccccccc<br>ddddddddd<br>eeeeeeeeeeeee",3,"飞飞Asp乐园|ffasp编程",",|.|。|,|@|!","ff0000"))
'请查看源源代码查看效果
'
'*********************************************
Dim EContent,UboundEContent,RndKeyWordArray,DomainLength,DomainPoint,TagName
Dim Keyword,ArryKeyword,ArryCountKeyword,KeywordLength,ArryUboundKeyword
Dim Sign,ArrySign,ArryUboundsign,SignLength
'------------------------------------------------------
Content=ReplaceReg(Content,"<br>","<br />",1)
Content=ReplaceReg(Content,"<br/>","<br />",1)
Content=ReplaceReg(Content,"</div>","</div>",1)
Content=ReplaceReg(Content,"</p>","</p>",1)
Content=ReplaceReg(Content,"</a>","</a>",1)
'-------------------------------------------------------
If instr(Content,"</a>")>0 Then 
TagName="</a>"
ElseIf instr(Content,"</div>")>0 Then
TagName="</div>"
ElseIf instr(Content,"</p>")>0 Then 
TagName="</p>"
ElseIf instr(Content,"<br />") Then
TagName="<br />"
Else 
TagName="</a>"
End If  
Randomize
'-------------------------------------------------------
RndKeyWordArray=""
EContent=split(Content,TagName)
UboundEContent=Ubound(EContent)
If UboundEContent+1-RndKeyWordCount<0 Then RndKeyWordCount=UboundEContent+1
Content=""
'--------------------------------------------------------
for i=1 to RndKeyWordCount
RndKeyWordArray=RndKeyWordArray&Int((UboundEContent+1) * Rnd)
If i<>RndKeyWordCount Then RndKeyWordArray=RndKeyWordArray&","
next
RndKeyWordArray=","&FormatReArray(RndKeyWordArray)&","
for i=0 to UboundEContent
'=====取出关键字========================== 
ArryKeyword=split(AllKeyword,"|")
ArryUboundKeyword=Ubound(ArryKeyword)
Keyword=ArryKeyword(int((ArryUboundKeyword+1)*Rnd))
KeywordLength=len(Keyword)



Content=Content&EContent(i)
If i<>UboundEContent Then Content=Content&TagName
If instr(RndKeyWordArray,","&i&",")>0 and i<>UboundEContent Then 

 DomainPoint=Int((KeywordLength) * Rnd + 1) 
  If DomainPoint=KeywordLength Then sign=""
  Content=Content&""&(Keyword)&"</br>"

End If 
Next
'--------------------------------------------------------
HiddenKeyword=Content
End Function
Response.Write(HiddenKeyword("aaaaaaaaaaaa<br />aaaaaaaaaaaa<br>aaaaaaaaaaaa<br>aaaaaaaaaaaa<br>aaaaaaaaaaaa",3,"测试1|测试2|测试3"))
%>

重复显示1个  
aaaaaaaaaaaa
测试1
aaaaaaaaaaaa
aaaaaaaaaaaa
测试1
aaaaaaaaaaaa
测试1
aaaaaaaaaaaa

怎么不重复显示呢 一个只显示一次呢
aaaaaaaaaaaa
测试2
aaaaaaaaaaaa
aaaaaaaaaaaa
测试1
aaaaaaaaaaaa
测试3
aaaaaaaaaaaa



2012-06-17 07:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-371679-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085598 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved