zoukankan      html  css  js  c++  java
  • 字母递增

     1      /// <summary>
     2         /// 过滤,取最大值
     3         /// </summary>
     4         /// <returns>Id</returns>
     5         public string FilteringId()
     6         {
     7             // 英字4桁のIdからMAX値取得
     8             var regex = new Regex(@"^[a-z]{4}$");
     9             string[] idList = this.XXRepo.All().Select(m => m.Id).ToArray();
    10             string maxId = idList.Where(m => regex.IsMatch(m) && m != "zzzz").Max();
    11             if (string.Empty.Equals(maxId))
    12             {
    13                 return "aaaa";
    14             }
    15             return this.NumberingForId(maxId);
    16         }
    17 //------------------------------cut-line---------------------------------------------------------
    18      /// <summary>
    19         /// 进位
    20         /// </summary>
    21         /// <param name="maxId">maxId</param>
    22         /// <returns>Id</returns>
    23         public string NumberingForId(string maxId)
    24         {
    25             int length = maxId.Length;
    26             char[] ch = new char[length];
    27             for (int i = 0; i < length; i++)
    28             {
    29                 ch[i] = maxId[i];
    30             }
    31             // 进位
    32             bool carry = true;
    33             int p = length;
    34             while (carry)
    35             {
    36                 p--;
    37                 ch[p] = this.LetterIncrement(ch[p]);
    38                 if (ch[p] == 'a')
    39                 {
    40                     carry = true;
    41                 }
    42                 else
    43                 {
    44                     carry = false;
    45                 }
    46             }
    47             return new string(ch);
    48         }
    49 //-------------------cut-line-------------------------------------------------
    50      /// <summary>
    51         /// 进位方法
    52         /// </summary>
    53         /// <param name="ch">ch</param>
    54         /// <returns>ch</returns>
    55         public char LetterIncrement(char ch)
    56         {
    57             if (ch == 122)
    58             {
    59                 ch = (char)97;
    60             }
    61             else
    62             {
    63                 ch++;
    64             }
    65             return ch;
    66         }
    View Code
  • 相关阅读:
    git branch用法总结
    vue-router异步加载组件
    vue错误提示 Cannot read property 'beforeRouteEnter' of undefined,刷新后跳到首页
    websocket常见错误
    Websocket原理
    怎么在overflow-y:sroll的情况下 隐藏滚动条
    URI和URL有什么区别
    确定浏览器是否支持某些DOM模块
    将nodeList转换为数组(兼容性)
    软件的三种版本
  • 原文地址:https://www.cnblogs.com/RocCnBlog/p/3383904.html
Copyright © 2011-2022 走看看