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

Line breakup (Separated with comma) 1

Status
Not open for further replies.

abbasaif

ISP
Oct 8, 2018
89
AE

Hi,

I have a long text field say (Inv)

Code:
PONO           DATE        INVOICE NOS.
===        =======    =======================================================================
PO100100 01/02/2019    JI225139,JI225140,JI225141,JI225143,JI225144,JI225145,JI225146,JI225147,JI225148,JI225149,JI225150,JI225151

How to break like this: length is exactly newinv c(8).

Code:
PONO           DATE        INVOICE NOS.
===        =======    =========
PO100100 01/02/2019    JI225139
PO100100 01/02/2019    JI225140
PO100100 01/02/2019    JI225141
PO100100 01/02/2019    JI225143
PO100100 01/02/2019    JI225144
PO100100 01/02/2019    JI225145
PO100100 01/02/2019    JI225146
PO100100 01/02/2019    JI225147
PO100100 01/02/2019    JI225148
PO100100 01/02/2019    JI225149
PO100100 01/02/2019    JI225150
PO100100 01/02/2019    JI225151

Please guide

Thanks
 
Use ALINES() to break the comma-delim string into an array:
[tt]
ALINES(laInvoices, InvNo, 0, ",")[/tt]

(Assumes the field containg the string is Invno; creates an array named laInvoices.)

Then loop through the array, copying each row to the relevant field in the output table.

The final code will depend on (i) whether the output table already exists; (ii) whether you want do this with a single comma-delim string or these strings are obtained from an input table, (ii) possibly other factors.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
or
Code:
? ExpandLine("PO100100 01/02/2019    JI225139,JI225140,JI225141,JI225143,JI225144,JI225145,JI225146,JI225147,JI225148,JI225149,JI225150,JI225151 ")

FUNCTION ExpandLine
	PARAMETERS m.LineIn
	PRIVATE m.LineIn, m.LineOut,i,m.InvoiceNo
	m.LineOut = ""
	FOR i = 0 TO ((LEN(m.LineIn)-23)/9)-1
		m.InvoiceNo = SUBSTR(m.LineIn,23+(i*9)+1,8)
		m.LineOut = m.lineOut + LEFT(m.LineIn,23)+m.InvoiceNo+CHR(13)+CHR(10)
	Next

	
	Return(m.LineOut)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Using ALINES instead:
Code:
*PONO           DATE        INVOICE NOS.
*===        =======    =======================================================================
*PO100100 01/02/2019    JI225139,JI225140,JI225141,JI225143,JI225144,JI225145,JI225146,JI225147,JI225148,JI225149,JI225150,JI225151 "
*12345678901234567890123

? ExpandLine("PO100100 01/02/2019    JI225139,JI225140,JI225141,JI225143,JI225144,JI225145,JI225146,JI225147,JI225148,JI225149,JI225150,JI225151 ")

FUNCTION ExpandLine
	PARAMETERS m.LineIn
	PRIVATE m.LineIn, m.LineOut,i
	m.LineOut = ""
	ALINES(laInvoices, SUBSTR(m.LineIn,24,255), 0, ",")
	FOR i = 1 TO ALEN(laInvoices)
		m.LineOut = m.lineOut + LEFT(m.LineIn,23)+laInvoices[i]+CHR(13)+CHR(10)
	Next

	
	Return(m.LineOut)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top