I have been trying to count the number of blank characters there are in each string below:
Peter Piper picked a peck of pickled peppers A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers, Where's the peck of pickled peppers Peter Piper picked?
I pine for the old mainframe days when you could use various REXX functions (POS, WORDPOS) to count the # of words etc., in a string. [Oh, and the early Elton John albums were awesome too!]
So far I have used CTRAN to translate the blanks' to '*', but I am stumped on how to accumulate the # of blanks in a string.
Any ideas?
Thanks,This message has been edited. Last edited by: Kerry,
DEFINE FILE CAR
INSTRLEN/D4 = ARGLEN(24, MODEL, 'D4');
OUTSTR/A24 = STRIP(24, MODEL, ' ', 'A24');
OUTSTRLEN/D4 = ARGLEN(24, OUTSTR, 'D4');
NBR_BLANKS/D4 = INSTRLEN - OUTSTRLEN;
END
TABLE FILE CAR
PRINT
MODEL
INSTRLEN
OUTSTR
OUTSTRLEN
NBR_BLANKS
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
September 25, 2008, 03:22 PM
Francis Mariani
I imagine you will see what the program is doing:
1) Determine the length of the string 2) Strip the blanks out of the string 3) Determine the length of the string without the blanks 4) Determine the number of blanks in the string by subtracting the length of the string without the blanks from the length of the string
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
Many Many years back. I had a simular situation where we needed to know how many times a certain character occurred in a field. We ended up creating our own userwritten subroutine. O the power of WebFOCUS/FOCUS.
Scott
September 25, 2008, 10:28 PM
susannah
frankie martini, that's so delightfully clever...
In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
September 25, 2008, 10:55 PM
Waz
Perhaps all WebFOCUS developers think alike.
I thought, this is simple, I'll add to the post, and found Francis pipped me at the post by a couple of posts.
A great concept to keep in mind. The field will always be the same length. STRIPping the spaces effectively left justifies all text or right justifies all spaces.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
September 26, 2008, 10:12 AM
Francis Mariani
It is a bit surprising that there isn't a supplied function to do this. We can easily convert my DEFINE code into a DEFINE FUNCTION so that it can be called from any program, passing only the character to be counted. One thing to remember is that if the character to be counted is not a space, then the existing spaces have to be CTRANed to something else before CTRANing the character to be counted!
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
September 28, 2008, 05:37 PM
Waz
Francis, thats a great idea.
A whitespace count, or at lease a define function with a parameter to choose space or whitespace.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
September 30, 2008, 03:30 AM
<JG>
2 alternative solutions 1 using POSIT and STRIP the other ARGLEN and STRIP