Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Count blanks in a string

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Count blanks in a string
 Login/Join
 
Master
posted
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? Idea

Thanks,

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


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
 
Posts: 573 | Location: Baltimore, MD | Registered: July 06, 2006Report This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Master
posted Hide Post
Thanks very much!


Tomsweb
WebFOCUS 8.1.05M, 8.2.x
APP Studio, Developer Studio, InfoAssist, Dashboards, charts & reports
Apache Tomcat/8.0.36
 
Posts: 573 | Location: Baltimore, MD | Registered: July 06, 2006Report This Post
Master
posted Hide Post
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

 
Posts: 865 | Registered: May 24, 2004Report This Post
Expert
posted Hide Post
frankie martini, that's so delightfully clever...




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
 
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003Report This Post
Expert
posted Hide Post
Perhaps all WebFOCUS developers think alike. Roll Eyes

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. Good One


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!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
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.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
<JG>
posted
2 alternative solutions 1 using POSIT and STRIP the other ARGLEN and STRIP

COMPUTE NBR_BLANKS1/I5 = 11 - (POSIT(STRIP(10, COUNTRY, ' ', 'A10'), 10, ' ', 1, 'I5'));
COMPUTE NBR_BLANKS2/D4 = 10 - (ARGLEN(10, STRIP(10, COUNTRY, ' ', 'A10'), 'D4'));
 
Report This Post
Gold member
posted Hide Post
TexasStingray:

Could please post your user-written subroutine to count spaces / characters in a string, field or file ?

We’d like to see how you accomplished this, and how it can be used efficiently in actual code, on large files.

Thanks


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
Master
posted Hide Post
It is available for download here

http://www.moonlightware.com

click on the Code Library.

you need FLASH 9 or higher to that website.




Scott

 
Posts: 865 | Registered: May 24, 2004Report This Post
Gold member
posted Hide Post
You say "O the power of WebFOCUS/FOCUS"

Is there a way to write a similar WebFOCUS routine without using external calls to another language ?

Thanks for the link !


WF 7.6.4 & 5.3
Charles Lee
 
Posts: 93 | Registered: June 17, 2008Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Count blanks in a string

Copyright © 1996-2020 Information Builders