Asp判断字符串中是否包含连续的重复字符

不允许字符串中连续重复超过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.tianzhigang.com"  
  2. if checkrepeat(text)=true then  
  3. response.Write("有重复超过2个的字符!")  
  4. else  
  5. response.Write("无重复超过2个的字符!")  
  6. end if  

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



上一篇: Javascript分割字符
下一篇: Php使用curl模拟浏览器采集网页
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: asp
相关日志:
评论: 0 | 引用: 0 | 查看次数: 3466
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑