....
Printable View
....
The explode and substr methods should get you what you want.
edit:
This is the PHP section.
I see you're using VB.NET which we have another section for.
Please don't create a new thread there though. I've already asked a moderator to move this thread.
But in that case you should look at the String.Split() and String.Substring() methods
Moved To VB.NET
Thanks for the report BigB! :thumb:
That's going to be a bit awkward to work with. I would split on : as a first step. This will result in an array of strings, but it will also split it further than you really want, so there would be another step. For one thing, the first element in the array would start with <, which you don't want, so use Substring to get rid of that (or ignore the first element, since it is just a label). Similarly, the last element in the array ends with >, which you will want to get rid of.
The next thing to note is that the time is array elements 1,2, and 3, while the date is array element 5. Lat will be element 7 and Long will be element 9 and so forth.
Please define how you would want to split the text.
Based on the sample text you provided, it looks like the lines have fixed length and so do the fields. The easiest way to parse it is to use String.Substring function.
See http://msdn.microsoft.com/en-us/library/zezabash.aspx. It has an example for files with text fields.
....
Or regex using this string:
Code:<time:(.+):date:(.+):lat:(.+):long:(.+):wind:(.+):temp:(.+):recipitation:(.+):visibility:(.+)>
Not directly. Regex is a means of matching strings by applying a pattern. That pattern is a derivative of a language in itself, and results in bizarre strings like the one Grimfort gave you (though that one is relatively mild as Regex patterns go). Look up Regex in MSDN for an example of how to work with it. You might also find this site to be a useful reference as to how to put together Regex strings:
http://www.regular-expressions.info/tutorial.html
vb.net Code:
'' put in imports section Imports Microsoft.VisualBasic.FileIO Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myData As New List(Of String()) Dim parser As New TextFieldParser("c:\temp\test.txt") parser.Delimiters = New String() {"<time:", ":date:", ":lat:", ":long:", ":wind:", ":temp:", ":precipitation:", ":visibility:", ">"} While Not parser.EndOfData myData.Add(parser.ReadFields) End While parser.Close() parser = Nothing '' lets see what we have in our list now. For Each row As String() In myData Debug.WriteLine(Join(row, vbTab)) Next End Sub
thanks i'll try out this code
.....
Is your textbox multiline?
Try this:
modify according to your needs.vb.net Code:
Private Sub Slice_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Slice_btn.Click Dim parser As New FileIO.TextFieldParser("D:\CT Year 2\Applications and VB\Assignments\sample2044ass2.txt") parser.Delimiters = New String() {"<time:", ":date:", ":lat:", ":long:", ":wind:", ":temp:", "recipitation:", ":visibility:", ">"} TextBox1.Text = Join(parser.Delimiters, vbTab) & vbCrLf While Not parser.EndOfData TextBox1.AppendText(Join(parser.ReadFields, vbTab) & vbCrLf) End While parser.Close() parser = Nothing End Sub
Yea both of my textboxes are multi lines
....