Loading...

          java .net

          C#實現(xiàn)類似Excel自動填充單元格,后面的數(shù)字累加

          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)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           

          公告

          希望有一天

          我能用鼠標(biāo)雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導(dǎo)航

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

          統(tǒng)計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網(wǎng)絡(luò)

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 颍上县| 浦北县| 仪陇县| 深水埗区| 晋宁县| 福清市| 安乡县| 湟源县| 尖扎县| 民乐县| 榆林市| 黔江区| 德惠市| 洛浦县| 南投县| 北海市| 抚顺县| 门头沟区| 清镇市| 莱西市| 兴隆县| 桂阳县| 镇沅| 福州市| 资源县| 新闻| 江阴市| 佛山市| 苗栗市| 任丘市| 平湖市| 建瓯市| 芒康县| 清涧县| 甘德县| 拉萨市| 敦化市| 托克逊县| 阿克陶县| 华宁县| 临沂市|