Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
static float billno = 2000;
billno = billno + 1;
textBox1.Text = billno.ToString();
Posted
Comments
Andreas Gieriet 17-Dec-15 7:04am    
So what is the question?
This is completely unclear. What do you try to achieve? You increment already, right?
Andi
MI_KRISHNAN 17-Dec-15 7:07am    
I need auto Increment like "ICPL/15/CL0055/M-01"
"ICPL/15/CL0055/M-02","ICPL/15/CL0055/M-03".....etc what to do
Andreas Gieriet 17-Dec-15 7:14am    
So you need a function which identifies the trailing number in a given string and increment that number? What if there is no trailing number? What if the number has less positions than needed, e.g. ABC-0, ... ABC-9, ABC-10 (makes two digits out of initially one)? Is it supposed to respect leading zeros? E.g. UVW-01, ... UVW-09, UVW-10 (or UVW-010)?
Cheers
Andi
MI_KRISHNAN 17-Dec-15 7:22am    
Initially starts with 01,02,03 and goes on upto 999
MI_KRISHNAN 17-Dec-15 7:46am    
I have another doubt
static float billno = ICPL/15/CL0055/M-01;
billno = billno + 1;
textBox1.Text = billno.ToString();


is it possible

1 solution

How about this?
C#
// Parses the given argument for a trailing number, increments that number by 1.
// Returns the newly creates string with the incremented number or null if there is no number to increment.
// Leading zeros are used up if a carry occurs.
// If there is no leading zeros, if a carry occurs, the number of digits is increased by one.
static string TryToIncrement(string tag)
{
    string result = null;
    Match m = Regex.Match(tag, @"^(.*?)(\d+)$");
    if (m.Success) {
        string head = m.Groups[1].Value;
        string tail = m.Groups[2].Value;
        string format = new string('0', tail.Length);
        int incremented = int.Parse(tail) + 1;
        result = head + incremented.ToString(format);
    }
    return result;
}
Cheers
Andi
 
Share this answer
 
Comments
BillWoodruff 17-Dec-15 12:43pm    
+5
Andreas Gieriet 17-Dec-15 12:49pm    
Thanks for your 5!
Cheers
Andi
[no name] 18-Dec-15 12:04pm    
No, I don't have a question or comment, but I let a 5 here.
Andreas Gieriet 19-Dec-15 13:06pm    
Thanks for your 5!
Cheers
Andi
Member 13353619 14-Aug-17 8:33am    
will it work with an sql server database?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900