-5 .net c# integer console-application
需要在整数名称前添加5位数0作为整数的记录号.它正在循环中使用,也在word文档中添加记录号.PLease提供任何解决方案.我已经尝试过以下事情,但没有按照以下方式工作
int recordnumber =1;
recordnumber.tostring("00000");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string[] stringArray1 = new string[2];
string[] stringArray2 = new string[2];
string[] stringArray3 = new string[2];
//ArrayList al = new ArrayList();
int customerId = 100000;
int customeraccount = 100001;
int accountnumber = 100000100;
int recordnumber = 1;
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
stringArray1[i] = "000001HE20140430CUSTOMER 01.00.00 \r\n" + recordnumber + "DA01" + customerId + " 00 8862019053100639390 00000-0085001-0 BISP BISP BISP 19830130BISP BISP 00000000000 BISP BISP BISP BISP BISP BISP 12345678910 12345678910 0120 ";
}
else
{
if (i == 1)
{
stringArray1[i] = recordnumber + "DA01" + customerId + " 00 8862019053100639390 00000-0085001-0 BISP BISP BISP 19830130BISP BISP 00000000000 BISP BISP BISP BISP BISP BISP 12345678910 12345678910 0120 \r\n002000FO20140430CUSTOMER";
}
else
{
stringArray1[i] = recordnumber + "DA01" + customerId + " 00 8862019053100639390 00000-0085001-0 BISP BISP BISP 19830130BISP BISP 00000000000 BISP BISP BISP BISP BISP BISP 12345678910 12345678910 0120 ";
}
}
if (i == 0)
{
stringArray2[i] = "000001HE20140430ACCOUNT 01.00.00\r\n" + recordnumber + "DA01120" + accountnumber + "001 20586BISP 88600";
}
else
{
if (i == 1)
{
stringArray2[i] = recordnumber + "DA01120" + accountnumber + "001 20586BISP 88600\r\n002000FO20140430ACCOUNT";
}
else
{
stringArray2[i] = recordnumber + "DA01120" + accountnumber + "001 20586BISP 88600";
}
}
if (i == 0)
{
stringArray3[i] = "000001HE20140430ACCOUNT_REL 01.00.00\r\n" + recordnumber + "DA01" + accountnumber + " 120886083001001 20586";
}
else
{
if (i == 1)
{
stringArray3[i] = recordnumber + "DA01" + accountnumber + " 120886083002001 20586\r\n002000FO20140430ACCOUNT_REL";
}
else
{
stringArray3[i] = recordnumber + "DA01" + accountnumber + " 120886083002001 20586";
}
}
//Convert.ToInt16(recordnumber);
recordnumber++;
accountnumber++;
customerId++;
customeraccount++;
}
StreamWriter file2 = new StreamWriter(@"d:\Tammeer_Imp0055.txt");
file2.WriteLine(String.Join(Environment.NewLine, stringArray1));
file2.WriteLine(String.Join(Environment.NewLine, stringArray2));
file2.WriteLine(String.Join(Environment.NewLine, stringArray3));
file2.Close();
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
string newstring = yourstring.PadLeft(6, '0');
要么
string formatted = yourstring.ToString("d6");
归档时间: |
|
查看次数: |
249 次 |
最近记录: |