Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 11th, 2006, 06:45 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regex with Special Characters

Hello Everyone and thanks for your help in advance. I am working on an application that needs to be able to parse the following strings out of a large block of text:

NM1*IL*1*LASTNAME*FIRSTNAME*X***MI*123456789~

The strings are using the * character for field delimiters (brilliant) and each stringn ends with the ~ character. The "NM1*IL*1*" is the same for all strings and the "MI" in the middle is also constant. Beyond that, everything is alpha or numeric. I'm really having a rough time with this because of all of the special characters. Any help on this topic would be greatly appreciated. Thanks.


Reply With Quote
  #2 (permalink)  
Old December 12th, 2006, 08:41 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

what did you try??
what's your specific problem??

did you try for example SPLIT?

HTH

Gonzalo
Reply With Quote
  #3 (permalink)  
Old December 13th, 2006, 09:28 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the general idea of what I am trying to do. I am working on a healthcare application that receives a text file in the HL7 format. HL7 uses a very odd file format that utilizes the * character for column separators and the ~ as the line terminator. So, for example, the first line could be:

ISA*00* *00* *ZZ*100000 *ZZ*71160~

The next line might be:

GS*HB*77027*71160*20061211*10341367*4*X*004010X092 A1~

Each element separated by a * character has a different meaning based on the beginning of the line (for example ISA vs. GS). The beginning of the line may vary slightly, such as GS*HB or GS*H1. So it owuld be advantageous to be able to match each line that starts with GS and ends with~. Some GS lines my have 5 elements, others may have 7, others may have 9. So identifying each type of line is needed to parse the file properly (couldn't they just use XML :)). But I can't figure out exactly how to do this.

Any insight is greatly appreciated. Thanks.


Reply With Quote
  #4 (permalink)  
Old December 14th, 2006, 01:42 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Dim arTemp() as string

arTemp = Split("YourStringHere")

IF ubound(arTemp) = 7 then

ElseIF ubound(arTemp) = 9 then

Else

End if

This should work.

If you are bit averse on arrays, ou can do the same in Regular Expressions

Cheers
Shasur

http://www.vbadud.blogspot.com
Reply With Quote
  #5 (permalink)  
Old December 15th, 2006, 03:16 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sililar to what Shasur proffered:
Code:
    Dim i as integer
    Dim arTemp As String
    arTemp = Split(<Your String Here>, "*")

    Select Case arTemp(0)
        Case "GS"
            ' Do an iterative process here.
            For i = 2 To Ubound(srTemp)
                ' . . .
            Next i

            ' or
            Select Case arTemp(1)
                Case "HB"
                    ' . . .
                Case "H1"
                    ' . . .
            End Select
        Case "ISA"
            [green]' . . .
    End Select
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML vs. special characters brko C# 1 January 23rd, 2006 11:05 AM
storing special special characters in nvarchar... ACE2084 SQL Server 2000 2 February 9th, 2005 11:45 AM
special characters lian_a Classic ASP Basics 3 June 23rd, 2004 05:16 AM
Special characters program meshteb Visual C++ 2 June 4th, 2003 09:07 AM



All times are GMT -4. The time now is 11:17 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.