×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

Microsoft: FoxPro FAQ

Program Source Code

How to SPLIT a String (ALINES) into an array? by wgcs
Posted: 22 Aug 05

This becomes easy in VFP 6 where the ALINES function was introduced, but is still possible in older versions if you use a UDF:

Call it like this:
DIMENSION OutArray[1] && any size.. will be redimensioned to fit
lnRows = Split(@OutArray, 'This,is,the,line', ',' )

CODE

FUNCTION Split
PARAMETERS paArr, pcLine, pcDiv
PRIVATE lnLen, lnWid, lnCnt, lnNum, lnStrt, lnPos, lcSub
lnLen = aLen( paArr, 1 ) && Number of rows
lnWid = aLen( paArr, 2 ) && Number of cols

lnCnt = OCCURS( pcDiv, pcLine+pcDiv )
if lnLen < lnCnt
if lnWid > 0
DIMENSION paArr[ lnCnt, lnWid ]
else
DIMENSION paArr[ lnCnt ]
endif
endif
lnStrt = 1
lnNum  = 0
do While atc( pcDiv, pcLine+pcDiv, lnNum+1 ) > 0
lnNum = lnNum + 1
lnPos = atc( pcDiv, pcLine+pcDiv, lnNum )
if lnStrt > len(pcLine) && 9/23/99 wgcs
lcSub = ''
else
lcSub = Substr( pcLine, lnStrt, lnPos-lnStrt )
endif
lnStrt = lnPos + len(pcDiv)
if lnWid > 0
paArr[ lnNum, 1 ] = lcSub
else
paArr[ lnNum ] = lcSub
endif
enddo

RETURN lnCnt

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

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!