INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

String Commands

Parsing Delimited Text by jimoo
Posted: 20 Oct 03 (Edited 21 Oct 03)

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.

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close