如何增加数字字符串? [英] How to increment numeric string ?
问题描述
大家好,
i有一个表单,其中有2个文本框,一个用于行,直到范围编号应该增加,第二个文本框初始输入
i想要增加数字字符串。
它是动态的
如果我有20行并且数字是0001
以下示例:
然后它应该递增并以字符串格式显示为
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
等等
和10美元之后
应该是
0010
0011
0012
0013
等等。
我怎样才能实现这个目标?
帮助将会很明显
谢谢
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
推荐答案
没有数字字符串和递增字符串这样的概念。您的问题反映了一个非常糟糕的趋势:使用表示数据的字符串而不是数据。你的数据首先不应该是字符串,它应该是一些合适的数字类型。
至于设置初始输入的文本框,这只是一个坏主意。你需要检查你的设计。
如果你解释了你的最终目标,我将能够解释更多。
-SA
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
您可以使用前导零填充您的号码,如下所示。在下面的示例中,它指定要打印的十进制数。如果你有一个数字,那么它将用3个前导零填充它。
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.
int number = 1;
string sNumber = number.ToString("D4");
请查看以下链接了解更多详情。
http://msdn.microsoft.com/ en-us / library / dd260048(v = vs.110).aspx
int length = invoiceNumberFormat.ToString().Length ;
string dValue = "D" + length.ToString();
这篇关于如何增加数字字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!