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.
Stacy, please edit your profile/signature so we know what version you're running. In 5n, i can show you how to do it the hard way, using both the POSITion function and the SUBSTRing function. The POSIT function will tell you where in the string a particular character or substring exists, with 0 meaning 'its not there'. and SUBSTR will then allow you to create a new test string from the original one, starting at the position+1 of the search character. Then repeat the process, searching the new substring until the POSIT function finally returns a 0. Count the number of times you have to do this in order to get a final 0. That's the count of your search chars.
In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
Posts: 3811 | Location: Manhattan | Registered: October 28, 2003
Here's a technique in DM that you can use. It can be particularly useful (when modified slightly) to perform character substitutions, such as replacing a single-quote with 2 consecutive single-quotes.
-* String to be searched
-SET &STRING = '~~~~12~~';
-* Character to count
-SET &SEARCHCHAR = '~';
-* Get the length of the string
-SET &STRING_LEN = &STRING.LENGTH;
-* Initialize the counter for the character being searched
-SET &CHARCOUNT = 0;
-* Initialize the loop index
-SET &IDX = 1;
-* Loop through the string a character at a time
-REPEAT :STRINGLOOP WHILE &IDX LE &STRING_LEN;
-* Get the next character in the string
-SET &CHARACTER = SUBSTR(&STRING_LEN, &STRING, &IDX,
- &IDX, 1, 'A1');
-* If the current character matches the string being searched
-* increment the count by 1
-SET &CHARCOUNT = IF &CHARACTER EQ &SEARCHCHAR THEN &CHARCOUNT + 1
- ELSE &CHARCOUNT;
-* Advance to the next character
-SET &IDX = &IDX + 1;
-:STRINGLOOP
-* Display the character count
-TYPE Character '&SEARCHCHAR' occurs &CHARCOUNT times in string '&STRING'
Regards, SeanThis message has been edited. Last edited by: smiths,
------------------------------------------------------------------------ PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
Posts: 210 | Location: Ottawa | Registered: November 03, 2005
I went ahead and tried Smiths's suggestion and it worked perfectly.
Because I never know the length of the long string, I also used drew's suggestions for ARGLEN to count the total number of characters in the string. This will limit the amount of loops it will do.
The reason I did that because if not then I would generally make the string an A4096 when that is not the case. Here is my solution with all of your suggestions below:
TABLE FILE T_FILENAME PRINT COMPUTE LENGTH/I4 = ARGLEN(4096, STRNG_X, LENGTH); AS LENGTH WHERE STRING_ID = &STRING_ID ON TABLE HOLD AS HOLDLENGTH END
TABLE FILE HOLDLENGTH PRINT LENGTH ON TABLE HOLD AS HOLDL FORMAT ALPHA END -RUN
TABLE FILE T_FILENAME PRINT STRNG_X WHERE STRING_ID = &STRING_ID ON TABLE HOLD AS HOLDSTRING END -RUN
-*** THIS HELPED ME SPECIFY THE LENGTH EACH TIME BY COUNTING THE CHARACTERS AND HELP MAINTIAN PERFORMANCE INSTEAD OF ASSUMING 4096 -SET &FORM = '.A'||&LENGTH;
No, there isn't. But you can still use drew's method, in DM as well as TABLE. An example of both, combined into one is:
-DEFAULT &CHARACTER = 'O'
-SET &STRING = 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG';
-SET &_BEFORE = ARGLEN(&STRING.LENGTH,&STRING,'I4');
-SET &STRIPPED = STRIP(&STRING.LENGTH,&STRING,&CHARACTER,'A&STRING.LENGTH');
-SET &_AFTER = ARGLEN(&STRIPPED.LENGTH,&STRIPPED,'I4');
-SET &NRTIMES = &_BEFORE - &_AFTER;
DEFINE FILE CAR
_BEFORE/I4 = ARGLEN(16,CAR,_BEFORE);
STRIPPED/A16 = STRIP(16,CAR,'&CHARACTER', STRIPPED);
_AFTER/I4 = ARGLEN(16,STRIPPED,_AFTER);
END
TABLE FILE CAR
"NUMBER OF TIMES &CHARACTER IS FOUND IN &STRING IS: &NRTIMES"
PRINT _BEFORE _AFTER
COMPUTE NRTIMES/I2 = _BEFORE - _AFTER;
BY COUNTRY
BY CAR AS ''
END
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007
There is a user-written sub-routine on www.moonlightware.com that will accomplish this. click on the code library to get the list. It's called chacter count. It contains instructions, C source code, and a dll that you can use if you are running the reporting server on windows.
Old thread but I thought I would add this for people looking in the future. This puts the character count logic into a re-usable function.
DEFINE FUNCTION COUNT_CHARS DESCRIPTION 'Returns the number of times a character occurs in a string.'(CHAR/A1,STRING/A4000V)
_BEFORE/I4 = ARGLEN(4000,STRING,'I4');
STRIPPED/A4000V = STRIP(4000,STRING,CHAR,'A4000V');
_AFTER/I4 = ARGLEN(4000,STRIPPED,'I4');
COUNT_CHARS/I4 = _BEFORE - _AFTER;
END
WF: WebFocus 8.0.02 InfoAssist, Dev Studio, Magnify, Portal/Dashboards, Mobile Favs Data: DB2 OS: Windows Output: Multiple
Posts: 23 | Location: KC, MO | Registered: August 05, 2013