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.