ADO DOT NET Posted January 28, 2007 Posted January 28, 2007 I use this code to read and split the first line of a text file: Dim LineIn As String Dim SStr() As String FileOpen(1, ("c:\file.txt"), OpenMode.Input) LineIn = LineInput(1) SStr = LineIn.Split(vbTab) FileClose(1) But in MSDN I red that: The FileOpen function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance. - I also found this example: Dim fileReader As String fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt") MsgBox(fileReader) The problem is that I cannot read just the first line of text file using new method. Also how can I close the file after reading? Thank you for your help:) Quote
*Experts* mutant Posted January 28, 2007 *Experts* Posted January 28, 2007 Look over the StreamReader object. This link to MSDN will help you and also give you an example of using the class: http://msdn2.microsoft.com/en-us/library/system.io.streamreader(VS.80).aspx Quote
Nate Bross Posted January 30, 2007 Posted January 30, 2007 If you read the whole length of the file into a string. You can use String.Split(Environment.NewLine()) to get data Line by line. Additionally, the System.IO namespace will be worth your while read about. The 'My' namespace is Visual Basic 2005 only, so using System.IO will work in any .NET Language. HTH Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Leaders snarfblam Posted January 30, 2007 Leaders Posted January 30, 2007 If you want to split a string into lines using String.Split, you might want to consider including Environment.NewLine, the CarriageReturn, and the LineFeed characters in the separators to cover all your bases (the correct line separator for Win32 is the CrLf but FTP and certain naughty apps might result in only the Cr or only the Lf). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.