c# - 检查文本框输入自动增加数量由输入总记录确定
问题描述
两个文本框用于检查输入结果以确定需要生成多少条记录。
第一个 用于自动递增编号的文本框:用户可能会输入“000000” 或“001000” 如果用户输入“ 090000 ”或“ 123456 ”,这部分会很棘手,请参阅代码变量getSequance。
用于检查总记录的第二个文本框需要生成参考代码变量 getrecords 。
我尝试自动增加最后一位数字:
private void input_autoincrement()
{
string getrecords = "10"; // first textbox:records generate
string getSequance = "000000"; //second textbox:auto increment number
for( int ix = 0; ix < Convert.ToInt32(getrecords); ix++)
{
string autoincrno = ix.ToString().PadLeft(1,'0'); // if autoincrno default value is "123456" how to make it change here?
}
}
我有一个问题,如果 autoincrno 具有默认值,例如“123456”,我这样做会将值重置为“000000”。
解决方案
如果我明白你在问什么,你想将 ix 转换为带有前导 0 的 6 位字符串
for( int ix = 0; ix < Convert.ToInt32(getrecords); ix++)
{
string autoincrno = ix.ToString("D6"); // 000001, 000002 etc
}
根据您的评论,如果您有一个表示数字的字符串并且想要增加它,您可以将其解析为整数。
string autoincro = "123456";
int temp = int.Parse(autoincrno);
temp++;
autoincrno = temp.ToString("D6"); // 123457
推荐阅读
- python - 仅将 GPU 用于 Tensorflow - Windows 10
- angular - Docker:运行 Angular 的最佳选择是什么?
- python - 在 django 的个人资料中显示用户帖子
- python - PyCharm 无法识别某些模块
- c++ - 您如何使用,并将参数传递给使用在 C++ 中的类中声明的变量和列表的函数?
- asterisk - Asterisk 与媒体同时拨出电话
- go - 使用 redigo 评估脚本时如何设置超时?
- tkinter - Tkinter:使用顶层避免新的标题栏
- c# - 无法使用 donet 核心 DPAPI 在 DLL 'crypt32.dll' 中找到名为 'CryptProtectMemory' 的入口点
- python - 虽然在 python 中不会打印所有行