Focal Point
[CLOSED] Text Formatting

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9397033196

May 30, 2019, 12:37 PM
DataCarniv0r
[CLOSED] Text Formatting
Hello, I have a field in a database that has a lot of text and I need to place sentences on a new line within a single compute virtual field when prefixed with a >>

I also need to look for words that have a double equals sign before and after the word and place them on their own line. So within one compute virtual field, I need to have this format:

==Prepare Muffins==
>>Get the flour
>>Get the sugar
>>Find some berries
==Bake The Muffins==
>>set oven to 350
>>grease a pan
>>place muffins in oven
>>set timer for 40 min

Right now, the data in the field looks like:

==Prepare Muffins==>>Get the flour>>Get the sugar>>Find some berries==Bake The Muffins==..and so on.

Is this possible with some text functions?

Using App Studio 8204
Thanks

This message has been edited. Last edited by: FP Mod Chuck,
May 30, 2019, 12:54 PM
BabakNYC
You'll have to use some of these functions in a DEFINE to accomplish this.
https://webfocusinfocenter.inf...cterSimplified70.htm


WebFOCUS 8206, Unix, Windows
May 30, 2019, 05:18 PM
Waz
Whats the output format ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 30, 2019, 08:34 PM
Hallway
quote:
Originally posted by Waz:
Whats the output format ?


Agreed. In order to answer this, we need to know what the output will be, since outputs have different answers.

There is probably a better way to do this, but this COMPUTE with nested functions works for HTML
  
-SET &TEXT = '==Prepare Muffins==>>Get the flour>>Get the sugar>>Find some berries==Bake The Muffins==>>set oven to 350>>grease a pan>>place muffins in oven>>set timer for 40 min';

TABLE FILE CAR
PRINT COMPUTE NEWFIELD/A200V = SUBSTRING(REPLACE(REPLACE(REPLACE(&TEXT.QUOTEDSTRING,'>>','<br>>>'),'==','<br>=='),'<br>==<br>>>','==<br>>>'),5,200);
BY COUNTRY NOPRINT
WHERE COUNTRY EQ 'ENGLAND'
ON TABLE SET PAGE-NUM NOPAGE
END




Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
May 30, 2019, 09:53 PM
Hallway
In JavaScript you can use the replace function using a regular expression. Copy/paste this code into the console of any modern browser (And no, IE is not a modern browser)
 
var oldText = '==Prepare Muffins==>>Get the flour>>Get the sugar>>Find some berries==Bake The Muffins==>>set oven to 350>>grease a pan>>place muffins in oven>>set timer for 40 min'
var newText = oldText.replace(/(?<=[a-z])={2}(?!>)|>{2}/g, '\n$&')
console.log(newText);
 

That will return the following to the console:
 
==Prepare Muffins==
>>Get the flour
>>Get the sugar
>>Find some berries
==Bake The Muffins==
>>set oven to 350
>>grease a pan
>>place muffins in oven
>>set timer for 40 min
 



Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
May 31, 2019, 09:46 AM
DataCarniv0r
Thanks for the replies. PDF is my output. What is my bet option then?

Thank you!
May 31, 2019, 10:26 AM
Tony A
Welcome DataMuncher,

Use Hallways first method but use HEXBYT(10,'A1') to insert a linefeed character instead of the the HTML breaks ( <br> ) then use LINEFEED='LF' within the styling.

Linefeed can be found in the help files here

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
May 31, 2019, 10:29 AM
DataCarniv0r
Sorry, just made a discovery. The carriage returns and line feeds are coming across fine in the SQL field I'm using. For example, when I copy that text from Oracle SQL Developer to Notepad, I can see the format as intended. Is there a way I can tell the field in App Studio to just observe the CRs and LFs that are stored in the text field?
May 31, 2019, 10:36 AM
Tony A
Yes, use the LINEFEED syntax within your styling. You need to have consistant characters in your data or just take a punt and specify just LINEFEED=CR or LINEFEED=LF.

This should be found in the documentation link that I gave.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
May 31, 2019, 11:27 AM
Hallway
quote:
Originally posted by DataCarniv0r:
Thanks for the replies. PDF is my output. What is my bet option then?

Thank you!


This works:
 
-SET &TEXT = '==Prepare Muffins==>>Get the flour>>Get the sugar>>Find some berries==Bake The Muffins==>>set oven to 350>>grease a pan>>place muffins in oven>>set timer for 40 min';

DEFINE FILE CAR 
NEWFIELD/A200V WITH COUNTRY = SUBSTRING(REPLACE(REPLACE(REPLACE(&TEXT.QUOTEDSTRING,'>>', CTRLCHAR(CR) | CTRLCHAR(LF) | '>>' ),'==', CTRLCHAR(CR) | CTRLCHAR(LF) | '=='),CTRLCHAR(CR) | CTRLCHAR(LF) |'=='|CTRLCHAR(CR) | CTRLCHAR(LF) |'>>','=='| CTRLCHAR(CR) | CTRLCHAR(LF) |'>>'),3,200);
END
TABLE FILE CAR
SUM NEWFIELD
ON TABLE PCHOLD FORMAT PDF
-* ON TABLE NOTOTAL
-* ON TABLE SET DROPBLNKLINE ALL
-* ON TABLE SET PAGE-NUM NOPAGE
-* ON TABLE SET CACHELINES 100
-* ON TABLE SET GRWIDTH 1
-* ON TABLE SET AUTOFIT OFF
ON TABLE SET STYLE *
TYPE=REPORT,LINEBREAK='CRLF',$
ENDSTYLE
END 


More here: CTRLCHAR: Returning a Non-Printable Control Character


Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
May 31, 2019, 11:29 AM
Hallway
quote:
Originally posted by Tony A:
Yes, use the LINEFEED syntax within your styling. You need to have consistant characters in your data or just take a punt and specify just LINEFEED=CR or LINEFEED=LF.

This should be found in the documentation link that I gave.

T


or if there is a CR and a LF, try:
 
TYPE=REPORT,LINEBREAK='CRLF',$



Syntax: How to Display An and AnV Fields Containing Line Breaks on Multiple Lines


TYPE=REPORT,LINEBREAK='type',$


where:



REPORT

Is the type of report component. TYPE must be REPORT. Otherwise an error will result.

'type'

Specifies that line breaks will be inserted in a report based on the following:

LF inserts a line break after each line-feed character found in all An and AnV fields.

CR inserts a line break after each carriage-return character found in all An and AnV fields.

LFCR inserts a line break after each combination of a line-feed character followed by a carriage-return character found in all An and AnV fields.

CRLF inserts a line break after each combination of a carriage-return character followed by a line-feed character found in all An and AnV fields.







More Here: Displaying Multi-Line An and AnV Fields

This message has been edited. Last edited by: Hallway,


Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs:
 
 
 
 
May 31, 2019, 11:54 AM
DataCarniv0r
Thank you both very much. It works like a champ, but now I have a new problem.

This works: I created a computed column using:
CTRAN(1000, MY_SQL_FIELD, 094, 013, Funding)

Then I added this to my source within the style section as per the docs:
TYPE=REPORT,LINEBREAK='CR',$

When I run it, it looks exactly as expected. I saved it. But when I switch to the Design tab, and then back to the Source tab, the TYPE=REPORT,LINEBREAK='CR',$ line I put in there is gone!

Is this a known issue or is there any workaround I can do?

Thanks
May 31, 2019, 12:13 PM
DataCarniv0r
I guess I could just add that line back in the source when I'm done with the entire report, and then save it. Not a big deal. Thanks again.
May 31, 2019, 01:06 PM
Hallway
quote:
Originally posted by DataCarniv0r:

When I run it, it looks exactly as expected. I saved it. But when I switch to the Design tab, and then back to the Source tab, the TYPE=REPORT,LINEBREAK='CR',$ line I put in there is gone!

Is this a known issue or is there any workaround I can do?

Thanks


There are a lot if issues with AppStudio reformatting/replacing code in the GUI. It get frustrating at times when the GUI doesn't even recognize valid FOCUS code like you are experiencing. If I ever use the GUI it is just to get the basic report laid out. I then open the report in VSCode (or any other text editor you may prefer) and edit the code in that if I need to do any tweaks.

Good luck.

This message has been edited. Last edited by: Hallway,


Hallway

 
Prod: 8202M1
Test: 8202M4
Repository:
 
OS:
 
Outputs: