Solved

Regex Pattern

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 46
VB.NET 2008 - Windows Protected Your PC 7 42
VB.net capture  result of a SQL query in variables 3 21
Code enhancement 4 22
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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