zoukankan      html  css  js  c++  java
  • 微博内容长度计算函数(C#)

    微博内容长度的计算方法(不一定完全无误,仅提供一个思路):

           public static int GetWeiboContentLength(string weiboContent)
           {
               var max = 140;
               var surl = 11;
               var urlCount = 0;

               RegexOptions ops = RegexOptions.Compiled;
               Regex regex = new Regex(@"http://[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_\$\.\+\!\*\(\)\/,:;@&=\?\~\#\%]*)", ops);
               var content = weiboContent;
               if (regex.IsMatch(weiboContent))
               {
                   var matchs = regex.Matches(weiboContent);
                   for (int i = 0; i < matchs.Count; i++)
                   {
                       var count = matchs[i].Groups[0].Length;
                       urlCount += count <= max ? surl : (count - max + surl);
                       content = content.Replace(matchs[i].Value, "");
                   }
               }
               var result = urlCount + content.Length;
               return result;
           }

    欢迎大家扫描下面二维码成为我的客户,为你服务和上云

  • 相关阅读:
    BigDecimal的一些用法
    java文件读写实例
    2017java文本文件操作(读写操作)
    java一些必会算法
    代码规范、如何写出好代码
    File available()方法
    Java当中的JVM
    分布式锁机制
    异常处理---抛与踹
    while eles
  • 原文地址:https://www.cnblogs.com/shanyou/p/2583837.html
Copyright © 2011-2022 走看看