0

Hello guys,
I have a small problem, and searching for solution. I am trying to write program that will write all numbers from 00000000 to 99999999 into txt file.
Result in txt should look like this
00000001
00000002
00000003
So, how can I do this?

Thanks

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by thines01
0

Here's one technique:

using System.IO;

namespace DW_398205
{
   class Program
   {
      static void Main(string[] args)
      {
         string strTempFileName = Path.GetTempFileName();
         using (StreamWriter fileOut = new StreamWriter(strTempFileName))
         {
            for (int i = 0; i < 100; i++)
            {
               fileOut.WriteLine("{0}", i.ToString().PadLeft(8, '0'));
            }

            fileOut.Close();
         }
      }
   }
}
0

Thanks very much… now I understand.
PadLeft(8, '0') was my biggest problem.
Thanks

1

Here's another technique:

using System.IO;

namespace DW_398205
{
   class Program
   {
      static void Main(string[] args)
      {
         string strTempFileName = Path.GetTempFileName();
         using (StreamWriter fileOut = new StreamWriter(strTempFileName))
         {
            for (int i = 0; i < 100; i++)
            {
               fileOut.WriteLine("{0}", i.ToString("D8"));
            }

            fileOut.Close();
         }

         File.Delete(strTempFileName);
      }
   }
}

And here is a reference: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString

Edited by thines01: Added reference

Votes + Comments
Great help! :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.