Loading...

          java .net

          C#實現類似Excel自動填充單元格,后面的數字累加

          class Program
              {
                  static void Main(string[] args)
                  {
                      Console.WriteLine(Next("abc123def345ghi"));
                      Console.Read();

                  }

                  private static string Next(string s)
                  {
                      if (!isNumber(s.Substring(s.Length-1,1)))
                          s = s + "0";
                      MatchCollection coll = Regex.Matches(s, @"\d+");
                      Match m = coll[coll.Count - 1];

                      return s.Substring(0, m.Index) + NextNum(m.Value);
                  }
                  private static string NextNum(string s)
                  {
                      char[] cs = s.ToCharArray();
                      for (int i = s.Length - 1; i >= 0; i--)
                      {
                          if (!NextChar(ref   cs[i])) break;
                      }
                    
                      string re = new string(cs);
                      if (Int32.Parse(re) == 0)
                          re = "1" + re;
                      return re;
                  }
                  private static bool NextChar(ref   char c)
                  {
                      string p = "01234567890123456789";
                      int n = p.IndexOf(c);
                      c = p[(n + 1) % 10 + 10 * (n / 10)];
                      return (n == 9 || n == 19);
                  }
                  public static bool isNumber(string str)
                  {
                      Regex r = new Regex(@"^\d+(\.)?\d*$");
                      if (r.IsMatch(str))
                      {
                          return true;
                      }
                      else
                      {
                          return false;
                      }
                  }

          posted on 2008-08-26 22:06 閱讀(815) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 克东县| 静安区| 贺州市| 柳河县| 体育| 昌图县| 金阳县| 社会| 延边| 塔河县| 调兵山市| 洛宁县| 无为县| 辽源市| 高碑店市| 西乌| 耿马| 台南市| 通江县| 佛冈县| 醴陵市| 耒阳市| 大同市| 泾川县| 祁东县| 琼中| 巴中市| 满洲里市| 丘北县| 巴彦县| 宁明县| 曲沃县| 上虞市| 河南省| 邻水| 庄浪县| 新晃| 贵南县| 平谷区| 集贤县| 塔河县|