Extracting and Parsing

  • Thread starter Thread starter Gdub58
  • Start date Start date
G

Gdub58

I receive unparsed data from a web originated text file.
The Qty, SKU, Product and Description all come into one
field called "Cart Contents", as shown in the following
example:
(Qty: 1 - Item: RD3487 - MEGA FIX; In this stunning,
surprisingly entertaining......

The Quantity (number only), the SKU (without the "Item:"
text or the hyphen) and the Product (always with the semi-
colon at the end) need to be parsed. Also, the
Description after the product is not needed.

I thank anyone in advance who can help or point me in the
right direction.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've used this function for situations like yours:

Function getToken(ByVal strSEARCH As String, ByVal strAhead As String, _
ByVal strAfter As String) As String
' Purpose:
' Return the string value between the strAhead token and the
' strAfter token.
' In:
' strSearch String to search thru.
' strAhead The token that indicates the beginning of the
' string we are looking for.
' strAfter The token that indicates the end of the sting we

' are looking for.
' Out:
' Success The substring between strAhead and strAfter.
' Failure An empty string.
' Created:
' mgf 9jul99
' Modified:
'

Dim p As Integer ' Position in string
Dim b As Integer ' Beginning position of string to return
Dim e As Integer ' Ending position of string to return

strSEARCH = Trim$(strSEARCH)
If Len(strSEARCH) > 0 Then
p = InStr(1, strSEARCH, strAhead)
If p > 0 Then
' We found the start of what we're looking for.
b = p + Len(strAhead)
If b < Len(strSEARCH) Then
' We are not at the end of the string.
e = InStr(b, strSEARCH, strAfter)
' If there isn't a strAfter in strSearch,
' read to end of string.
If e = 0 Then e = Len(strSEARCH) + 1
' We have our string.
getToken = Mid$(strSEARCH, b, (e - b))
End If
End If
End If

End Function

Call it like this:

strWebSring = "(Qty: 1 - Item: RD3487 - MEGA FIX; In this stunning, "

dim intQty as integer
dim strSKU as string
dim strProduct as string

intQty = getToken(strWebString, "Qty: ", " - ")
strSKU = gettoken(strWebString, "Item: ", ";")
strProduct = getToken(strSKU, " - ", ";")
strSKU = getToken(strSKU, "", " - ")

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQVMjCoechKqOuFEgEQLJXwCgpDGmg9JKbHM+LZdJT+iy6XGk+CkAoLUa
1uqgAm4oqSwhFbGNE1bJBW8t
=Up3o
-----END PGP SIGNATURE-----
 
Back
Top