add a CRLF to a line of text

Started by MW4, May 15, 2015, 01:44:19 PM

Previous topic - Next topic

MW4

Hi there I have a need to add a CRLF at certain points in a line and I an unsure of how to do so.

I have a text file that every line ends in a CRLF.
Most lines have one item of data--A descriptor, then a colon then the data, like the TOTAL CUSTOMER CHARGES See Data 1 below.
Sometimes the data is blank--there's a descriptor, but no data.

As you can see from Data 2 the spot where the descriptor starts is variable in each instance

What I'd like to see is Data 3 obtained from Data 1.
(CRLF)'s are invisible in my real text.

Your thoughts??


DATA SET 1
*****************************************************
*****************************************************
Roof Type: N/A Contact Name: MR. ROBERTS (CRLF)
Sales Type: Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: STANDARD Contact Name: MR. SMITH (CRLF)
Sales Type: CIP Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 1/1/2015 Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 10/10/2015 Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 1/10/2015 Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 10/1/2015 Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)

DATA SET 2
*****************************************************
*****************************************************
Roof Type: N/A Contact Name: MR. ROBERTS
Roof Type: STANDARD Contact Name: MR. SMITH
Roof Type: HIGH Contact Name: MR. PIPPIN

Should be:

Roof Type: N/A
Contact Name: MR. ROBERTS

Roof Type: STANDARD
Contact Name: MR. SMITH

Roof Type: HIGH
Contact Name: MR. PIPPIN
*****************************************************
Sales Type: Contact Phone: XXX-XXX-XXXX Ext.
Sales Type: CIP Contact Phone: XXX-XXX-XXXX Ext.
Sales Type: FLTPRG Contact Phone: XXX-XXX-XXXX Ext.

Should be:

Sales Type:
Contact Phone: XXX-XXX-XXXX Ext.

Sales Type: CIP
Contact Phone: XXX-XXX-XXXX Ext.

Sales Type: FLTPRG
Contact Phone: XXX-XXX-XXXX Ext.
*****************************************************
Update Date: Contact Email: XXXXX@XXXXX.com
Update Date: 1/1/2015 Contact Email: XXXXX@XXXXX.com
Update Date: 10/10/2015 Contact Email: XXXXX@XXXXX.com
Update Date: 1/10/2015 Contact Email: XXXXX@XXXXX.com
Update Date: 10/1/2015 Contact Email: XXXXX@XXXXX.com

Should be:

Update Date:
Contact Email: XXXXX@XXXXX.com

Update Date: 1/1/2015
Contact Email: XXXXX@XXXXX.com

Update Date: 10/10/2015
Contact Email: XXXXX@XXXXX.com

Update Date: 1/10/2015
Contact Email: XXXXX@XXXXX.com

Update Date: 10/1/2015
Contact Email: XXXXX@XXXXX.com
*****************************************************


DATA SET 3
*****************************************************
*****************************************************
Roof Type: N/A (CRLF)
Contact Name: MR. ROBERTS (CRLF)
Sales Type: (CRLF)
Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: (CRLF)
Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: STANDARD (CRLF)
Contact Name: MR. SMITH (CRLF)
Sales Type: CIP (CRLF)
Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 1/1/2015 (CRLF)
Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH (CRLF)
Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG (CRLF)
Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 10/10/2015 (CRLF)
Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH (CRLF)
Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG (CRLF)
Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 1/10/2015 (CRLF)
Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)
Roof Type: HIGH (CRLF)
Contact Name: MR. PIPPIN (CRLF)
Sales Type: FLTPRG (CRLF)
Contact Phone: XXX-XXX-XXXX Ext. (CRLF)
Update Date: 10/1/2015 (CRLF)
Contact Email: XXXXX@XXXXX.com (CRLF)
TOTAL CUSTOMER CHARGES: $400.00 (CRLF)
------------------------------- (CRLF)




mhall

Well if the descriptor is always going to be formatted the same, how about using StrReplace() to insert the @CRLF prior to the descriptor you want to break onto the next line?

As in:

data_set = strReplace( data_set, desc, @CRLF:desc )


As you have a list of descriptions you want to insert an @CRLF prior to, you could use a list and loop over it.



;// data_set is your data
desc_list = 'Contact Name:|Contact Phone:|Contact Email:'
desc_count = itemCount( desc_list, '|' )

for d = 1 to desc_count
   desc = itemExtract( d, desc_list, '|' )
   data_set = strReplace( data_set, desc, @CRLF:desc )
next



MW4