|
-
Mar 10th, 2011, 01:56 PM
#1
Thread Starter
New Member
Last edited by MGCL21; Mar 31st, 2011 at 09:25 AM.
-
Mar 10th, 2011, 02:28 PM
#2
Re: String Slicing
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
Delete it. They just clutter threads anyway.
-
Mar 10th, 2011, 02:31 PM
#3
Re: String Slicing
Moved To VB.NET
Thanks for the report BigB!
-
Mar 10th, 2011, 03:35 PM
#4
Re: String Slicing
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.
My usual boring signature: Nothing
 
-
Mar 10th, 2011, 04:45 PM
#5
Re: String Slicing
Please define how you would want to split the text.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Mar 10th, 2011, 07:04 PM
#6
Thread Starter
New Member
Re: String Slicing
 Originally Posted by stanav
Please define how you would want to split the text.
I would like the text split up into seperate cells into an excel spreadsheet.
-
Mar 10th, 2011, 08:40 PM
#7
Re: String Slicing
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.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Mar 11th, 2011, 05:42 AM
#8
Thread Starter
New Member
Re: String Slicing
 Originally Posted by stanav
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.
Is it still possible if the text length is variable?
-
Mar 11th, 2011, 08:07 AM
#9
-
Mar 17th, 2011, 11:12 AM
#10
Thread Starter
New Member
Last edited by MGCL21; Mar 31st, 2011 at 08:27 AM.
-
Mar 17th, 2011, 11:22 AM
#11
Re: String Slicing
Or regex using this string:
Code:
<time:(.+):date:(.+):lat:(.+):long:(.+):wind:(.+):temp:(.+):recipitation:(.+):visibility:(.+)>
-
Mar 24th, 2011, 08:51 AM
#12
Thread Starter
New Member
Re: String Slicing
 Originally Posted by Grimfort
Or regex using this string:
Code:
<time:(.+):date:(.+):lat:(.+):long:(.+):wind:(.+):temp:(.+):recipitation:(.+):visibility:(.+)>
what do you mean by regex? if i copy this code into my current code will it work?
-
Mar 24th, 2011, 09:52 AM
#13
Re: String Slicing
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
My usual boring signature: Nothing
 
-
Mar 24th, 2011, 10:01 AM
#14
Re: String Slicing
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
-
Mar 24th, 2011, 10:21 AM
#15
Thread Starter
New Member
Re: String Slicing
thanks i'll try out this code
-
Mar 24th, 2011, 10:49 AM
#16
Thread Starter
New Member
Last edited by MGCL21; Mar 31st, 2011 at 08:27 AM.
-
Mar 24th, 2011, 01:58 PM
#17
Re: String Slicing
Is your textbox multiline?
Try this:
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
modify according to your needs.
-
Mar 24th, 2011, 08:45 PM
#18
Thread Starter
New Member
Re: String Slicing
Yea both of my textboxes are multi lines
-
Mar 31st, 2011, 08:09 AM
#19
Thread Starter
New Member
Last edited by MGCL21; Mar 31st, 2011 at 08:27 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|