Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing text files 2

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have an app that looks at a folder and waits for text files. When one arrives, it opens the file. I ned to parse it when it finds "$$$" in the text.

A sample of the text in the file would be like this:

AB:::Withold 99296123$$$Reason is unknown

I need a string that is everything up to and including the $$$ as one string and everything after the $$$ to be a separate string

How can I do this?

Thanks

fergmj
 
Hi,

My suggestion is:

Read the file into one string (see e.g. faq222-482).
Use instr to find the "$$$"
parse the strings using left$ and mid$:

'assume your file-string is called MyStr.
FirstStr=left$(MyStr,instr(1,MyStr,"$$$")-1)
SecondStr=mid$(MyStr,instr(1,MyStr,"$$$")+3)

:) Sunaj
 
It's easy peasy, although I'll probably get told off for saying so.


Dim c As String
Dim i As Integer
Dim cLeftBit As String
Dim cRightBit As String

c = "AB:::Withold 99296123$$$Reason is unknown"

i = InStr(c, "$$$")
If i > 0 Then

cLeftBit = Left$(c, i - 1 + 3)
cRightBit = Right$(c, Len(c) - i - 2)

End If

if you don't understand the code, look the 3 functions up in help. if still stuck, ask again
Peter Meachem
peter@accuflight.com
 
Great comments from both Peter and Sunaj. All is working great.

THANKS to both!

fergmj
 
Sorry, I thought I did that. I've done it now.

:)

fergmj
 
You could also use the Split method

'assume your file-string is called MyStr.

Code:
dim sStringParts() as string

sStringParts = Split(MyStr, "$$$")

Output will be an array.

Jordi Reineman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top