Substrinig(a,b):

从下标a开始截取,共截取b位

 

 实现:一串数字,中间两位数字+2,生成新的一串数字

    
    string number="1301302016001003";
    string a = number.Substring(0, number.Length - 8);//前8位
    string b = number.Substring(number.Length - 6);//后6位
    string c = number.Substring(number.Length - 8,2);//第9,10位
    
    int d = int.Parse(c.ToString()) + 2;    //将string转为int,加2
    if (d < 10)
    {
        c = d.ToString().PadLeft(2, '0');    //PadLeft(2, '0'),保留两位,若不足,左边补0
    }
    else
    {
        c = d.ToString();
    }
    number = a + c + b;

 

 posted on 2016-11-10 15:46  布鲁布鲁sky  阅读(3649)  评论(0编辑  收藏  举报