Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i have one form in which there are 2 textboxes one for rows till what range number should increment and second textbox initial input


i want to increment numeric string.
it is dynamic
If i have 20 rows and have number is "0001"
following example:


then it should be incremented and shown in string format as
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
and so on




and one it comes to 10 onwards

it should be
0010
0011
0012
0013

and so on.





how can i achieve this?
help will be appreciable

thanks
Posted
Updated 18-Aug-14 3:26am
v2

There is no such concepts as "numeric string" and "increment a string". Your question reflects a very bad trend: to work with strings representing data, instead of data instead. Your data should not be in string in first place, it should be in some appropriate numeric type.
As to the text box setting up "initial input", this is just a bad idea. You need to review your design.

If you explain your ultimate goals, I will be able to explain more.

—SA
 
Share this answer
 
Comments
Maciej Los 18-Aug-14 15:01pm    
+5
Sergey Alexandrovich Kryukov 18-Aug-14 16:11pm    
Thank you, Maciej.
—SA
You can pad your number with leading Zeros as below. In below example it specifies how many Decimal numbers to print. If you have one digit number then it will pad it with 3 leading Zeros.

C#
int number = 1;
string sNumber = number.ToString("D4");


Have a look at below link for more details.

http://msdn.microsoft.com/en-us/library/dd260048(v=vs.110).aspx
 
Share this answer
 
Comments
shivani 2013 18-Aug-14 9:16am    
leading zeros are dynamic.there can be 2 , 3 , 4 depending upon user
RaisKazi 18-Aug-14 11:54am    
It will add dynamic no of Zeros, based on number of digits in your number.
Sergey Alexandrovich Kryukov 18-Aug-14 12:54pm    
That's correct (I voted 4), but you did not address the root problem. The data should not be a string in first place. Please see my answer.
—SA
C#
int length = invoiceNumberFormat.ToString().Length ;
                string dValue = "D" + length.ToString();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Aug-14 12:56pm    
Please see the comments to Solution 2. The format is not known in advance. But you can calculate the format itself, depending on input. (I voted 4.)
The real problem is bad OP's design. Please see my answer.
—SA
Try This
suppose
tb1=20
tb2=0001
int YourNo=Convert.ToInt32(tb2.text);

for(int i=YourNo;i>=i+Convert.ToInt32(tb1.text);i++)
{
    String sNo1=i.ToString("0000");
}
 
Share this answer
 
v3
Comments
shivani 2013 18-Aug-14 9:08am    
thanks for reply.its dynamic .... for more clarification i have updated my question.
sandip1711 18-Aug-14 9:18am    
Please check Solution.
Hope this will work

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