xSea xSea - 1 month ago 16
C# Question

How to set for loop value all to 0 in MVC C#

I have this IdNo which contains 2letter and 7 digit just like how our identity card number.
The following code is in an Else statement whereby I have to do a loop to count characters because this it might no be necessarily 9 characters i might be more.

for(int j=0;j<idNo.Length;j++)
{
what to put here?
to set the 9 character to 0??
}
;

Answer

You can do this

string zeroes= new String('0', idNo.Length);

basically what it is, the '0' is the character you with to repeat inNo.Lengths times

Comments