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

parsing string

Status
Not open for further replies.

abdellatif99

Programmer
Jun 26, 2002
11
LY
how can i parse this string

"my intersting is reading"
 
X="my intersting is reading"

substring(string,start,number of spaces)

?substr(x,1,2)
returns "my"

substr(x,15,2)
returns "is"

There are other functions that help as well. Check out the list of them in the help file under "Character Functions".

Brian
 
AT() is also helpful:

OrigStr = "my intersting is reading"
DO WHILE ' ' $ OrigStr
tmpStr = LEFT(OrigStr, AT(' ', OrigStr))
?tmpStr
OrigStr = LTRIM(SUBSTR(OrigStr, AT(' ', OrigStr)))
?? ' ' + OrigStr
ENDDO
?OrigStr

Dave S.
 
If you have 7.0, you can also use GETWORDCOUNT() and GETWORDNUM(). In earlier versions of VFP you can use Words() and Wordnum() in FoxTools. (Both require much less code!)

Rick
 
If you don't use FoxTools or VFP7, in VFP6 you can use ALines as in:
Code:
lcStr = "Whatever you want to parse. More words;something else."

lcWorkStr = CHRTRAN(lcStr,'.;:-"!@#$%^&*()','               ')  && Convert separators to spaces
nWords = ALINES( aWords, StrTran(lcWorkStr,' ',Chr(13) )
* Now, nWords is the word count
*  and aWords is an array of the words.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top