[RESOLVED] Isolating text strings from a file
Howdee all :wave: !
I have an application that hacks down a text file for viewing/db import. While its working now(with help from folks here, thanks :) !) I have a new problem. one field that already gets seperated out for display/view needs to be refined further.
There is a general text "block" that has to be seperated into three seperate text strings so the DB import can put them into the appropriate fields. The three strings have their own desiginator characters, and I thought I would just parse the string then hold them into seperate memory spaces via varible declarations in the import sub function. Problem is, I'm not sure how parse/seperate the text in VB6 because I'm THAT much of a newbie.
The seperators are -
No characters is the basic problem description that comes in originally.
XXX denotes update remarks for the particular entry.
/// OR \\\ denotes a close to the entry in question.
EXAMPLE -
Original problem gets listed, it's usually a fairly short string. XXX Problem gets some sort of update text. XXX Maybe some more update text gets added here. /// Then they close the problem report for that particular entry like this.
Can anyone explain to me how to pull this off?
John
Re: Isolating text strings from a file
Post a block that you want to parse
Re: Isolating text strings from a file
4320010205 N/ADURING NORMAL OPERATION, DISCOVERED MALFUNTIONING * IN SUPPLY OFFICE. UPON INVESTIGATION FOUND WORN GEARS DUE TO BROKEN TENSION SPRING.
XXX REQUEST NEW * FROM SUPPLY SYSTEMTO REPAIR STATION IN SUPPLY OFFICE.XXX SUPPLY INDICATES NO * LEFT ON BOARD, REQUEST TO RECEIVE PARTS DURING PORT CALL.\\\XXX PARTS RECEIVED ALL WORK COMPLETED, NO FURTHER ACTIONS REQUIRED.
This is what one typically looks like. The * is text I removed. Can't let everyone see that stuff :rolleyes: .
The "XXX" at the end after "\\\" would be removed in the viewer before export.
Re: Isolating text strings from a file
This is hideously bad code, but it works on the first example you gave.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim strExample As String
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim slash As String
strExample = "Original problem gets listed, it's usually a fairly short string. XXX Problem gets some sort of update text. XXX Maybe some more update text gets added here. /// Then they close the problem report for that particular entry like this."
str1 = Left$(strExample, InStr(strExample, "XXX") - 1)
str2 = Mid$(strExample, InStr(strExample, "XXX") + 3, InStrRev(strExample, "XXX") - (InStr(strExample, "XXX") + 3))
If InStr(strExample, "///") > InStr(strExample, "\\\") Then
slash = "///"
Else
slash = "\\\"
End If
str3 = Right$(strExample, Len(strExample) - InStr(strExample, slash) - 2)
Debug.Print str1
Debug.Print str2
Debug.Print str3
End Sub
Also works for example in post #3 (with the last XXX removed).
Re: Isolating text strings from a file
Yep, works like a charm. Now I just have to figure a way to work with the inconsistencies of the reporting.
Thanks!
John