Solved

Regex Pattern

Posted on 2006-07-11
2
299 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now