Focal Point
Using strrep to replace a period

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

October 29, 2007, 04:08 PM
gweller
Using strrep to replace a period
I am attempting to strip out the period located within my username to allow me to make a nice pretty title. Any thoughts on the problem behind this one? It complains about the period. It will work with other characters.

STRREP(&USR.LENGTH, '&USR.EVAL', 1, '.', 1, 'X', &USR.LENGTH, 'A&USR.LENGTH')

Error: INVALID TYPE OF ARGUMENT #4 FOR USER FUNCTION STRREP


WebFOCUS 8201M/Windows Platform
October 29, 2007, 04:11 PM
gweller
nevermind...

I searched on the error message and found this piece of advice.."Concat an empty string to the end to force into an alphanumeric" so...

STRREP(&USR.LENGTH, '&USR.EVAL', 1, '.' | '', 1, ' ' | '', &USR.LENGTH, 'A&USR.LENGTH');


WebFOCUS 8201M/Windows Platform
October 29, 2007, 04:17 PM
Francis Mariani
Or you could use CTRAN to replace one character by another.

-DEFAULT &USR = 'Francis.Mariani';
-SET &USR1 = CTRAN(&USR.LENGTH, &USR, BYTVAL('.','I2'), BYTVAL(' ','I2'), 'A&USR.LENGTH');

-TYPE &USR / &USR1

In my example, using BYTVAL avoids having to use the ASCII/EBCDIC decimal values for the character to be replaced and makes the CTRAN function platform-independent.


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
October 29, 2007, 05:10 PM
Trav
I don't know if this is the same issue or not, but we've had issues with "short" strings and using STRREP sometimes completely strips out all of the characters.

In the end, our solution is exactly what you've found -- concatenate some spaces to the end. I've always thought this strange, but for us it seemed to be more frequent on strings that were less than say 4 characters or so.



Production: 7.6.6 WF Server  <=>  7.6.6 WF Client  <=>  7.6.6 Dev Studio
Testing: <none>
Using MRE & BID.  Connected to MS SQL Server 2005
Output Types: HTML, Excel, PDF