none
Read File RRS feed

  • Question

  • Let's say I have a file that I don't know how many lines it has.  I want to read the contents of the file and put those contents in an array.  Here's a code snippet that I know works OK, but I don't know if it is the best way of doing it.  So, my question is:  "Is there a better way to read an unknown size file and put it in an array than the way I did it?"

    x=1
    Data=file.ReadLine("c:\Test.dat",x)
    While Data <> ""
      Array.SetValue("Array",x,Data)
      x=x+1
      Data=file.ReadLine("c:\Test.dat",x)
    EndWhile
    Count=Array.GetItemCount("Array")
    For x=1 To Count
      TextWindow.WriteLine(Array.GetValue("Array",x))
      endfor

    P.S.  To setup Test.dat I just used notepad and entered some lines in it.

    Thanks,

    JR
    Sunday, May 3, 2009 1:15 AM
    Answerer

Answers

  • I don't see any better.
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    • Marked as answer by Dudeson Friday, January 29, 2010 12:08 AM
    Sunday, May 3, 2009 7:53 AM