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     [CLOSED] Character Count

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Character Count
 Login/Join
 
Platinum Member
posted
Is it possible to count the number of ~'s or any such character found in the a long string?


Thank you,
Stacy

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


Dev, SIT, UAT, Production:7.6.6
Dev Sandbox:7.6.11

Dev Studio - 7.6.6
 
Posts: 178 | Registered: May 11, 2005Report This Post
Expert
posted Hide Post
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, 2003Report This Post
Platinum Member
posted Hide Post
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,
Sean

This 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, 2005Report This Post
Silver Member
posted Hide Post
you might want to do an ARGLEN() then a STRIP() and then an ARGLEN() to see how many characters the STRIP() removed. (start_len - end_len)


WF 7.6.6 Linux, FOCUS 7.8 zOS
 
Posts: 46 | Location: San Francisco, California | Registered: April 14, 2003Report This Post
Platinum Member
posted Hide Post
Sorry about that Susanne. I am using version 534.

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

-READ HOLDL &LENGTH.A4
-SET &LENGTH = INT(&LENGTH);

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;

-READ HOLDSTRING &STRING.&FORM
-SET &STRING = &STRING;

-SET &SEARCHCHAR = '~';
-SET &STRING_LEN = &STRING.LENGTH;
-SET &CHARCOUNT = 0;
-SET &IDX = 1;

-REPEAT :STRINGLOOP WHILE &IDX LE &STRING_LEN;

-SET &CHARACTER = SUBSTR(&STRING_LEN, &STRING, &IDX,
- &IDX, 1, 'A1');

-SET &CHARCOUNT = IF &CHARACTER EQ &SEARCHCHAR THEN &CHARCOUNT + 1
- ELSE &CHARCOUNT;

-SET &IDX = &IDX + 1;
-:STRINGLOOP



Thank you so much to everyone that gave input. This has helped me very much!

---------------------------------------------
DEV: v534
UAT: v534
PROD: v534

Moving to 7.1 for Dev soon!


Dev, SIT, UAT, Production:7.6.6
Dev Sandbox:7.6.11

Dev Studio - 7.6.6
 
Posts: 178 | Registered: May 11, 2005Report This Post
Expert
posted Hide Post
some pretty clever stuff here! very nice.




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
Guru
posted Hide Post
How about for Version 7n+ ... Is there a direct function for accomplishing this ?


Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
 
Posts: 394 | Location: Chennai | Registered: December 02, 2009Report This Post
Virtuoso
posted Hide Post
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, 2007Report This Post
Master
posted Hide Post
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.

Hope this helps




Scott

 
Posts: 865 | Registered: May 24, 2004Report This Post
Member
posted Hide Post
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, 2013Report 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     [CLOSED] Character Count

Copyright © 1996-2020 Information Builders