预览模式: 普通 | 列表

不允许字符串中连续重复超过2次,可以在发布信息网站禁止标题中发布某些无意义的重复字符!

ASP/Visual Basic代码
  1. function checkrepeat(txt)  
  2.     checkrepeat=false  
  3.     initialtxt=""  
  4.     num=1  
  5.     for i=1 to len(txt)  
  6.         character=mid(txt,i,1)  
  7.         if character=initialtxt then  
  8.             num=num+1  
  9.         else  
  10.             num=1  
  11.         end if  
  12.         initialtxt=character  
  13.         if num>2 then  
  14.             checkrepeat=true    
  15.         end if  
  16.     next  
  17. end function  

调用方法:

ASP/Visual Basic代码
  1. text="www.jlist.cn"  
  2. if checkrepeat(text)=true then  
  3. response.Write("有重复超过2个的字符!")  
  4. else  
  5. response.Write("无重复超过2个的字符!")  
  6. end if  

原创代码,转载请注明出处!http://www.jlist.cn

查看更多...

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3467

 广告位

↑返回顶部↑