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 閱讀(813) 評論(0)  編輯  收藏


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


          網站導航:
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

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

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 黄梅县| 达孜县| 铜川市| 牡丹江市| 佛教| 栾川县| 齐齐哈尔市| 满城县| 鞍山市| 马山县| 方城县| 察隅县| 工布江达县| 桃园市| 英山县| 应城市| 娱乐| 丰宁| 禹城市| 原平市| 揭西县| 平原县| 阆中市| 盱眙县| 马公市| 农安县| 丰都县| 冀州市| 陆丰市| 玉溪市| 卢龙县| 饶河县| 原阳县| 五指山市| 塔城市| 航空| 青铜峡市| 恩施市| 淮阳县| 旌德县| 安溪县|