Member Avatar for cool_intentions

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

Recommended Answers

All 3 Replies

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();
         }
      }
   }
}
Member Avatar for cool_intentions

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

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

commented: Great help! :) +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.