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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Delimited Text

String Commands

Parsing Delimited Text

by  jimoo  Posted    (Edited  )
Example One
* Just replace one string of text with another:

lcString = "Hello World; I am Fine; How Are You?"
lcString = StrTran(lcString,";",".")
MESSAGEBOX(lcString)


Example Two
* make each item an individual string
* strip out the semi-colin (;)


* lcString = "Dog"
lcString = "Dog;Cat;Deer;Fox;Goat"
lnLoopCount = OCCURS(";",lcString )
FOR lni = 1 TO lnLoopCount + 1
lnPos = ATC(";",lcString)
IF lnPos > 0
lcValue = LEFT(lcString,(m.lnPos -1))
lcString = SUBSTR(lcString,ATC(";",lcString)+1)
ELSE
lcValue = lcString
ENDIF
MESSAGEBOX(lcValue)
ENDFOR

Example Three
* this example parses our ; but keeps the rest as one string.
lcString = "Dog;Cat;Deer;Fox;Goat"
lcString = StrTran(lcString,";","")
MESSAGEBOX(lcString)

OR if you need a little more control for some IF / ELSE processing

* lcString = "Dog"
lcString = "Dog;Cat;Deer;Fox;Goat"
lcValue = ""
lnLoopCount = OCCURS(";",lcString )
FOR lni = 1 TO lnLoopCount + 1
lnPos = ATC(";",lcString)
IF lnPos > 0
lcValue = lcValue + LEFT(lcString,(m.lnPos -1))
lcString = SUBSTR(lcString,ATC(";",lcString)+1)
ELSE
lcValue = lcValue + lcString
ENDIF
ENDFOR
MESSAGEBOX(lcValue)



* Other functions you may wish to consider when paring code include:

ALINES()
ALLTRIM()
ATC()
GETWORDNUM()
LTRIM()
PADL()
PADR()
RTRIM()
STREXTRACT()
STUFF() && insert, replace, or delete text


Refer to VFP help for more information on these functions.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top