Solved

Regex Pattern

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET Application Installation with sqlserver 8 69
make control visible based off other control value 7 45
Need help with another query 10 54
Web page design problem 3 41
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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