Solved

Regex Pattern

Posted on 2006-07-11
2
300 Views
Last Modified: 2010-04-23
Hi. I have a text file with the following structure.

field1|field2|field3|field4

I am reading the complete text file to one string.

As you can see, fields are seperated by "|". What I want to do is a search in this text file. File contains more than 2000 rows. For the speed problems, I down want to use loop structure. If it's possible, I want to use regex. But I dont know the pattern that I should use to search the specific value in the fields. For example I need the values of field1 which field3 contains "X1" or the values of filed4 where field2 is equal to "CA". "Contains" and "equal" verbs are important.

Thanks
0
Comment
Question by:gokhanoz
2 Comments
 
LVL 8

Accepted Solution

by:
plq earned 250 total points
ID: 17081604
Personally I dislike regex because the expressions are hard to read and not understood my many programmers.

What about this

dim sBuffer as string = ReadTextFile("...")
dim sRecords() as string = sBuffer.Split(vbCrLf)
for i as integer = 0  to sRecord.Length - 1
   dim sRecord as string = sRecords(i)
   if sRecord(i) <> "" then
      dim sFields() as string = sRecord(i).Split("|")
      if sFields(3) = "X1" then
          bSearchFound = true
      end if
 ....

Maybe it can be done with regex, lets see what others say...
0
 

Author Comment

by:gokhanoz
ID: 17096989
I was waiting for REGEX answer, but your answer is also possible. So, thanks alot.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question