Ace Master Posted September 15, 2003 Posted September 15, 2003 hi. Who can give me a good example of text file parse ? I have a text file and I whant to take some parts of it and put into some variables. thanks a lot. Quote
Ace Master Posted September 15, 2003 Author Posted September 15, 2003 it is possible to create an array with text file elements and then to show in the form just the array element that I want? Quote
Administrators PlausiblyDamp Posted September 15, 2003 Administrators Posted September 15, 2003 What does the contents of the text file look like? Are we talking some kind of structured file (TSV, CSV etc) or a more free form layout? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ace Master Posted September 15, 2003 Author Posted September 15, 2003 this is how the file looks: 1 44.12345 25.56789 Ianca 2 41.78909 24.56789 Bechet values are separated by "space" for row 1 I have 44.12345 > var1 25.56789 > var2 Ianca > var3 etc....for the rest of the rows. is a matter of life and death :) Quote
Administrators PlausiblyDamp Posted September 15, 2003 Administrators Posted September 15, 2003 Dim sr As New System.IO.StreamReader("c:\test.txt") Dim line As String Dim vals() As String Do line = sr.ReadLine() If line Is Nothing Then Exit Do vals = line.Split(" ") 'vals will contain an array of the data for each line. Loop While Not line Is Nothing bit rough but should do the trick Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ace Master Posted September 16, 2003 Author Posted September 16, 2003 (edited) thanks, but how I take the values ? for vals(1) I receive 41.78909 for 0 is ok...for 2 or 3 is ok..but the problem is that the array contain the last line (second line) I can't extract from array elements from first line. a little help here.....thanks Edited September 16, 2003 by Ace Master Quote
Ace Master Posted September 16, 2003 Author Posted September 16, 2003 done...weird stuff here. I take out the loop from the code and now is working. :) many thanks Quote
Ace Master Posted September 16, 2003 Author Posted September 16, 2003 (edited) enter problem I see that I have aother problem: The vals(5) for ex. is the last from the line and this variable contain an "enter" , and I want to ignore this "enter" from the array. One way is to take it out from the file source but it looks bad. what I need to do ?:confused: Edited September 16, 2003 by Ace Master Quote
Ace Master Posted October 17, 2003 Author Posted October 17, 2003 I tried to make a bidimensional array to put some values like this : Dim sr As New System.IO.StreamReader("ace.txt") Dim vals() As Object Dim Line As Object Line = sr.ReadToEnd vals = Line.Split("," & vbCrLf) sr.Close() text file is like this: 1,158 2,258 3,689 4,489 5,789 I whant this: TextBox1.Text = vals(1)(2) to return 158 TextBox1.Text = vals(3)(2) to return 689 etc... but..it seams not to work... Quote
Leaders dynamic_sysop Posted October 18, 2003 Leaders Posted October 18, 2003 you might want to try the ReadLine() property in this way .... Dim sr As New System.IO.StreamReader(New System.IO.FileStream("C:\ace.txt",System.IO.FileMode.Open)) While Not sr.Peek() Console.WriteLine(sr.ReadLine.Split(",")(1)) '/// you can use the Replace function here if you have returns to remove ( eg vbcrlf , chr(10) , chr(13) and so on ) '/// for example Console.WriteLine(Replace(sr.ReadLine.Split(",")(1) , VbCrlf , "")) End While sr.Close() Quote
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.