I am writing a program that has to read a text file for a string that is surrounded by [ ]. I then want to grab the text behind it which is surrounded by ( ). The string i want to grab is in the same line as the one i searched for. So far i have been able to read the file and i looked everywhere for a solution on how to get the string but none of them worked. Please help me.
megax24505
0
Newbie Poster
Recommended Answers
Jump to PostSample input and output please.
Jump to PostYou can read the entire file into a string array as
Dim allLines() As String = System.IO.File.ReadAllLines(MYFILE)
and you can extract the "interesting" lines as
Dim myLines() As String = Filter(allLines,"[String I'm searching for]")
The array, myLines, will contain only the lines …
Jump to PostI just used "line" as a generic string variable.
For Each line As String in myLines MsgBox(Trim(line.Split("]")(1))) Next
Would display the requested text from each matching line.
line.Split("]")
splits the line into two strings using "]" as the delimiter
Jump to PostAnd if each line is different then
For Each line As String In System.IO.File.ReadAllLines("d:\temp\test.txt") Dim lb As Integer = InStr(line, "[") Dim rb As Integer = InStr(line, "]") 'make sure line has "[" followed by "]" If lb > 0 And rb > 0 And rb > …
Jump to PostWhen I used to work for a living I would get requests from my users to write programs or to modify existing ones. My usual first response was to write up, in my own terms, what it was I thought they were asking for. I would ask them to either …
All 21 Replies
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Reverend Jim
4,780
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
megax24505
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.