求助:ASP.NET中如何实现字符串的自动增减,比如string x="00001",加1后变成00002,加9后变成00010,……

解决方案 »

  1.   


    var a= 1;
    var b= 2;
    var c= "0000" + ( parseInt(a) + parseInt(b) );
    c= c.substring(c.length-5,c.length );
      

  2.   

    使用存储过程生成流水号:
    --下面的代码生成长度为8的编号,编号以BH开头,其余6位为流水号。
    --得到新编号的函数
    CREATE FUNCTION f_NextBH()
    RETURNS char(8)
    AS
    BEGIN
    RETURN(SELECT 'BH'+RIGHT(1000001+ISNULL(RIGHT(MAX(BH),6),0),6) FROM tb WITH(XLOCK,PAGLOCK))
    END
    GO--在表中应用函数
    CREATE TABLE tb(
    BH char(8) PRIMARY KEY DEFAULT dbo.f_NextBH(),
    col int)--插入资料
    BEGIN TRAN
    INSERT tb(col) VALUES(1)
    INSERT tb(col) VALUES(2)
    INSERT tb(col) VALUES(3)
    DELETE tb WHERE col=3
    INSERT tb(col) VALUES(4)
    INSERT tb(BH,col) VALUES(dbo.f_NextBH(),14)
    COMMIT TRAN--显示结果
    SELECT * FROM tb
    /*--结果
    BH         col 
    ---------------- ----------- 
    BH000001  1
    BH000002  2
    BH000003  4
    BH000004  14
    --*/
      

  3.   

    private void Format(string baseValue, int addValue)
    {
        string result = (int.Parse(baseValue) + addValue).ToString();
        int length = result.Length;
        for (int i=0; i<5-length ; i++)
        {
            result = "0" + result;
        }
        return result;
    }
      

  4.   

    string str = "00001";
    int curstr = Convert.ToInt32(str);
    string nextstr = (curstr+1).ToString(); int len = str.Length;
    int i = nextstr.Length;
    while(i<len)
    {
    nextstr = "0"+nextstr;
    i++;
    }
      

  5.   

    你到时候把str作为参数传进来就可以了,为了测试,我暂时把它设为了 "00001";
      

  6.   

    简单一点:数字前补0int i=3;
    string s=i.ToString().PadLeft(6,'0');