Focal Point
[SOLVED] Does anyone have a technique for coloring a portion of a string

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

December 23, 2008, 09:03 AM
hammo1j
[SOLVED] Does anyone have a technique for coloring a portion of a string
Standard styling will color whole strings, but I want to highlight where in a string a search match has occurred. eg we are searching for lmno
and the result is

abcdefghijklmnopqrstuvwxyz

Has anyone come up with a nifty technique for doing this. I searched the forums and came up with diddley.

What would be awesome would be that it worked for html, pdf, exl2k, but HTML only would be enough.

Here's hoping

John

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



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
December 23, 2008, 10:21 AM
Tom Flynn
Hi John,

THANKS!! for getting my mind working this morning!!! Appreciate it...

You'll have to play around with the POSIT stuff when the string is in different places, AND,
I couldn't get the dynamic field format to work in a DEFINE,
BUT, this works:

  
-SET &SEARCH = 'lmno';
-SET &LEN    = &SEARCH.LENGTH;
DEFINE FILE CAR
COL1/A26 = 'abcdefghijklmnopqrstuvwxyz';
COL1_A1/I2 = POSIT(COL1, 26, '&SEARCH', &LEN , 'I2');
COL1_A2/A4 = SUBSTR(26, COL1, COL1_A1, COL1_A1+3, 4, COL1_A2);
-******************************************************************
COL1_B1/I2 = IF COL1_A1 EQ 1 THEN &LEN ELSE COL1_A1 - 1;
COL1_C1/I2 = COL1_B1 + &LEN;
COL1_D1/I2 = IF COL1_C1 EQ 26 THEN 26 ELSE 26 - COL1_C1;

XFMT1/A8   = IF COL1_B1 EQ 0 THEN  'A' ||  EDIT(COL1_D1)
               ELSE 'A' ||  EDIT(COL1_B1) ;
XFMT2/A8   = IF COL1_D1 EQ 0 THEN 'A' ||  EDIT(COL1_B1)
               ELSE 'A' ||  EDIT(COL1_D1) ;
END
TABLE FILE CAR
SUM
  XFMT1
 BY COUNTRY NOPRINT
IF RECORDLIMIT EQ 1
 ON TABLE SAVE
END
-RUN
-READ SAVE &XFMT1.A8.
-TYPE &XFMT1
TABLE FILE CAR
SUM
  XFMT2
 BY COUNTRY NOPRINT
IF RECORDLIMIT EQ 1
 ON TABLE SAVE
END
-RUN
-READ SAVE &XFMT2.A8.
-TYPE &XFMT2
TABLE FILE CAR
SUM
    COL1_A1
    COL1_A2
    COL1_B1
    COL1_C1
    COL1_D1
    XFMT1
    XFMT2
    COMPUTE COL1_A3/&XFMT1 = SUBSTR(26, COL1, 1, COL1_B1, COL1_B1, COL1_A3);
    COMPUTE COL1_A4/&XFMT2 = SUBSTR(26, COL1, COL1_C1, 26 , COL1_D1, COL1_A4);
    COMPUTE SHOW_DATA/A300 = '<FONT color="black">' | COL1_A3 | '</FONT>' | '<FONT color="red">' | COL1_A2 | '</FONT>' | '<FONT color="black">' | COL1_A4 | '</FONT>';
 BY COUNTRY
END
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 23, 2008, 10:33 AM
Francis Mariani
Here's another solution for HTML only:

-SET &ECHO=ALL;

-SET &SEARCH = 'A';

-SET &STRREP = '<span class=hi>' || &SEARCH || '</span>';

TABLE FILE CAR
PRINT
COMPUTE COUNTRYX/A100 =
  STRREP (10, COUNTRY, 2, '&SEARCH', &STRREP.LENGTH, '&STRREP', 100, 'A100');

WHERE COUNTRY LIKE '%&SEARCH|%'

ON TABLE HOLD AS H001 FORMAT HTMTABLE
END
-RUN

-HTMLFORM BEGIN
<html>
<head>
<style type="text/css">
.hi { color: red; }
</style>
</head>

<body>
!IBI.FIL.H001;
</body>
</html>
-HTMLFORM END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 23, 2008, 10:39 AM
Tom Flynn
Francis,

EXCELLENT!!!

Great idea - this is much better! I always take the long and winding road!!

Now, if Mickey see's this, he may assist with the PDF version!!!

Tom


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 23, 2008, 12:44 PM
hammo1j
Good work both Tom and Francis

Ironically Francis' technique seems simpler but if you uppercase the string in order to do a case unsensitive search you still have to use Tom's technique to reinsert into the original not uppercased string.

I'm thinking as well along lines of letting wf do the work of generating a red class by putting a dummy entry into the styling sheet and using that in the class statements. That avoids the HTMLFORM but could be a bit risky seeing that the names of the styles .x1, .x2 etc could change.

Thanks for your ideas - both of you.



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo
December 23, 2008, 12:55 PM
Tom Flynn
John,

Glad it is working out for you. Both ideas also work for EXCEL with:

SET HTMLFORMTYPE = XLS

Safe and Happy Holiday's to all.

Tom


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 23, 2008, 01:13 PM
hammo1j
You too Tom

Have never seen HTMLFORMTYPE = XLS. Will try.

BTW if you want PDF look alike with html try FORMAT DHTML.

Tried to do this

TYPE=DATA,COLOR=RED,WHEN=1 EQ 2, $

Hoping wf would define a class that it never uses but for a class to be in the HTML generated it needs to be referenced so it looks like -HTMLFORM it is.

Regards

John



Server: WF 7.6.2 ( BID/Rcaster) Platform: W2003Server/IIS6/Tomcat/SQL Server repository Adapters: SQL Server 2000/Oracle 9.2
Desktop: Dev Studio 765/XP/Office 2003 Applications: IFS/Jobscope/Maximo