Hi I don;t knwo if anyone has a solution for this problem but i need some code to read and extract the data between two characters in VB.NET. This one has really stumped me and i would just like part of the code because i can prob do the rest. Any help would be greatly appreciated. Thanks in advance!!!
Reading between two characters in a text fileAnyone know?
Page 1 of 1
4 Replies - 13646 Views - Last Post: 23 January 2007 - 08:08 PM
Replies To: Reading between two characters in a text file
#2
Re: Reading between two characters in a text file
Posted 21 January 2007 - 10:55 AM
Assuming those two characters are part of String object, you can pinpoint the locations of those characters using the InStr() method, and then return what you need using the .Substring() method of the string object using the two positional coordinates obtained from the first part.
#3
Re: Reading between two characters in a text file
Posted 21 January 2007 - 01:36 PM
Beng, on 18 Jan, 2007 - 09:49 PM, said:
Hi I don;t knwo if anyone has a solution for this problem but i need some code to read and extract the data between two characters in VB.NET. This one has really stumped me and i would just like part of the code because i can prob do the rest. Any help would be greatly appreciated. Thanks in advance!!!
Use mid() functon.
Hope it helps
#4
Re: Reading between two characters in a text file
Posted 23 January 2007 - 03:59 PM
Thanks i am grateful for the response but with the mid function how do you get it to move down one line when reading say the mid can't find a certian character in that line so it automatically moves down one line?
Thanks again!
Thanks again!
#5
Re: Reading between two characters in a text file
Posted 23 January 2007 - 08:08 PM
Beng, on 23 Jan, 2007 - 03:59 PM, said:
Thanks i am grateful for the response but with the mid function how do you get it to move down one line when reading say the mid can't find a certian character in that line so it automatically moves down one line?
Thanks again!
Thanks again!
Was there a question made? Or even many in 1?
1) How to use multi line mid
2) Can Mid find a certain character in line, so it would understand to take next line
3) Can i read data in with mid, at certain part of line
Chop it up before, and then you can move any way you want. I made an example that i think would answer your question.
Private Function Lose_The_Log_Date(Optional ByVal MyFileName As String = "C:\MyData.ptf") As String
Lose_The_Log_Date = ""
Try
For Each x As String In My.Computer.FileSystem.ReadAllText(MyFileName).Split(Chr(13))
Lose_The_Log_Date &= Chr(13) & Mid(x, 10, 30)
Next x
Catch ex As IO.IOException
MsgBox("Be brave; There Was An Error")
End Try
End Function
And second example is for showing how to read in data between some string.
Private Overloads Function Open_Tag(ByVal DataToBeInspected As String, _ ByVal BetweenWhat As String) As String Dim Turn_To_Find_Opening As Boolean = True Open_Tag = "" For i As Integer = 1 To Len(DataToBeInspected) Select Case Turn_To_Find_Opening Case True If Mid(DataToBeInspected, i, Len(BetweenWhat)) = BetweenWhat Then Turn_To_Find_Opening = Not Turn_To_Find_Opening End If Case Else If Mid(DataToBeInspected, i, Len(BetweenWhat)) = BetweenWhat Then Turn_To_Find_Opening = Not Turn_To_Find_Opening Open_Tag &= "|" Else Open_Tag &= Mid(DataToBeInspected, i, 1) End If End Select Next i End Function Private Overloads Function Open_Tag(ByVal DataToBeInspected As String, _ ByVal Starting As String, _ ByVal Ending As String) As String Dim Turn_To_Find_Opening As Boolean = True Open_Tag = "" For i As Integer = 1 To Len(DataToBeInspected) Select Case Turn_To_Find_Opening Case True If Mid(DataToBeInspected, i, Len(Starting)) = Starting Then Turn_To_Find_Opening = Not Turn_To_Find_Opening End If Case Else If Mid(DataToBeInspected, i, Len(Ending)) = Ending Then Turn_To_Find_Opening = Not Turn_To_Find_Opening Open_Tag &= "|" Else Open_Tag &= Mid(DataToBeInspected, i, 1) End If End Select Next i End Function
If you want to test how does it work, then you can test it with:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim tekst As String = _ "/* How does it work? " & Chr(13) & _ "Lorem ipsum" & Chr(13) & _ "Lorem ipsum" & Chr(13) & _ "Lorem ipsum*/" & Chr(13) & Chr(13) & _ "And now some content." & Chr(13) & _ "/* How does it work 2? " & Chr(13) & _ "Lorem ipsum" & Chr(13) & _ "Lorem ipsum" & Chr(13) & _ "Lorem ipsum*/" & Chr(13) & Chr(13) & _ "And now some content2." Dim a As String = Open_Tag(tekst, "/*", "*/") MsgBox(tekst) MsgBox(a) End Sub
Hope it helped alot
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|