?
Solved

Regex Pattern

Posted on 2006-07-11
2
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
plq earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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