Your problem is i
is still an integer, it needs to be assigned to a string
for (int i = 1; i <= 36; i++)
{
var iString = i.ToString();
if(iString.Length == 1)
{
iString = iString.PadLeft(2,'0'); //RIGHT HERE!!!
}
Response.Write("Test: " + iString);
}
However, much of this code is superflous, the if
statement is not needed. Pad will only ped with zeroes up to the length (2) given. If it's already 2 or more characters long, it won't pad anything. All you need is this
for (int i = 1; i <= 36; i++)
{
var iString = i.ToString().PadLeft(2,'0');
Response.Write("Test: " + iString);
}
For that matter, the variable is no longer needed.
for (int i = 1; i <= 36; i++)
{
Response.Write("Test: " + i.ToString().PadLeft(2,'0'));
}
And if you'll be padding with zeroes all the time, and not some other character, you could just do this
for (int i = 1; i <= 36; i++)
{
Response.Write("Test: " + i.ToString("00"));
}
And you should get into the habit of using string.Format
for (int i = 1; i <= 36; i++)
{
Response.Write(string.Format("Test: {0}", i.ToString("00")));
}
And to simplify the string.Format
even further:
for (int i = 1; i <= 36; i++)
{
Response.Write(string.Format("Test: {0:00}", i));
}