C# 如何获取数组的计数?公司# char[]charArray=startno.ToCharArray(); //使用此arry //我要支票 int i=0; 计数=0; while(chenum[i]!=“0”) { 计数++; i++; } 字符串s=“0”; 字符串0=“0”; 对于(i=1;i
请尝试C# 如何获取数组的计数?公司# char[]charArray=startno.ToCharArray(); //使用此arry //我要支票 int i=0; 计数=0; while(chenum[i]!=“0”) { 计数++; i++; } 字符串s=“0”; 字符串0=“0”; 对于(i=1;i,c#,.net,asp.net,C#,.net,Asp.net,请尝试int.parseInt(startNo)而不是将其转换为char数组。需要多少个零??可以使用string.pad char[] charArray = startno.ToCharArray(); //using this arry //i want to cheque this int i=0; count = 0; while (chenum [i] != "0") { count++; i++; } strin
int.parseInt(startNo)
而不是将其转换为char
数组。需要多少个零??可以使用string.pad
char[] charArray = startno.ToCharArray();
//using this arry
//i want to cheque this
int i=0;
count = 0;
while (chenum [i] != "0")
{
count++;
i++;
}
string s = "0";
string zero = "0";
for (i = 1; i <= count; i++)
{
s = s + zero;
}
还有数字格式化程序
int count = 1102;
int NumOfZeros = 10;
string s = count.ToString().PadLeft(NumOfZeros, '0');
如果您将此数字存储为int(您应该这样做),则1102 annd 000011102是相同的。稍后当您需要输出带有一些零的值时,请使用字符串格式
1102.ToString(“D8”)
将为您提供字符串“00001102”
另外,这个问题可能重复:您需要使用
String.Format(“{0:00000000}”,1101);
,即00001101我想将其作为00001102@RAHUL:它是用作数字还是字符串?PadLeft非常灵活。我从未注意到它。我一直使用字符串格式化程序。谢谢!
count.ToString("D10");
String num = "000001101";
int item = int.Parse(num);
item++;
String output = item.ToString("D8");