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)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 且末县| 邹城市| 天津市| 社旗县| 分宜县| 台北市| 开平市| 甘孜| 太仆寺旗| 金华市| 资源县| 钟山县| 肃宁县| 哈巴河县| 桓仁| 轮台县| 涪陵区| 广丰县| 宜兴市| 遵化市| 安多县| 巫山县| 分宜县| 克拉玛依市| 锦州市| 淳化县| 弋阳县| 志丹县| 桐乡市| 富源县| 建瓯市| 营山县| 垣曲县| 余江县| 桂林市| 昌宁县| 温泉县| 区。| 伊通| 房山区| 新营市|