Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Find specific word in a string
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Find specific word in a string
 Login/Join
 
Platinum Member
posted
Hello,
is there a function to find a specific word in a string and to count it. i need this for a flexible
html-form. in the form i want to make a drilldown on a specific coloum, but the coloumnumber is flexible.

thanks a lot

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


WF Production Version: 7.7.02M
WF Test Version: 7.7.02M
Developer Studio: 7.7.02
HTML, EXL2K, FLEX, PDF,PPT
 
Posts: 156 | Location: Essen Germany | Registered: December 02, 2010Reply With QuoteReport This Post
Virtuoso
posted Hide Post
quote:
is there a function to find a specific word in a string
Look up the POSIT function, it does just that.
quote:
and to count it
Now that's a different thing. WebFocus does not have any standard procedure that can do that for you. So you'll have to think up some workaround to get the count. Search this forum for that, I'm sure there is some thread that can give you a hint on how to do that.


GamP

- Using AS 8.2.01 on Windows 7 - IE11.
in Focus since 1988
 
Posts: 1960 | Location: Netherlands | Registered: September 25, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
quote:
Originally posted by GamP:
quote:
and to count it
Now that's a different thing. WebFocus does not have any standard procedure that can do that for you. So you'll have to think up some workaround to get the count. Search this forum for that, I'm sure there is some thread that can give you a hint on how to do that.


Are we talking a count of the number of letters or count of the number of occurences of whatever word youre looking for?


WebFOCUS: 7702
O/S : Windows
Data Migrator: 7702
 
Posts: 127 | Location: San Antonio | Registered: May 29, 2009Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Here is a possible solution. I used Dialogue Manager but with some minor changes this should work in a DEFINE, too. First replace the search string ('car' in this example) with a single character that won't ever appear in your text string (I used the tilde ~ here). Next remove that character from the second string. The difference between the lengths of the second and third strings will give you the number of occurrences of the search string in the original string. The search string 'car' appears four times in the original string.

-SET &TEXT1     = 'this car that car those cars all have "scars"!';
-SET &TEXT2     = STRREP(&TEXT1.LENGTH,&TEXT1,3,'car',1,'~',&TEXT1.LENGTH,'A&TEXT1.LENGTH');
-SET &TEXT3     = STRIP(&TEXT2.LENGTH,&TEXT2,'~','A&TEXT2.LENGTH');
-SET &TEXT2_LEN = ARGLEN(&TEXT2.LENGTH,&TEXT2,'I3');
-SET &TEXT3_LEN = ARGLEN(&TEXT3.LENGTH,&TEXT3,'I3');
-SET &COUNTX    = &TEXT2_LEN - &TEXT3_LEN ;
-TYPE &TEXT1
-TYPE &TEXT2
-TYPE &TEXT3
-TYPE &TEXT2_LEN
-TYPE &TEXT3_LEN
-TYPE &COUNTX


If you need to find whole words, then put spaces around the search string (i.e., ' car '):

-SET &TEXT2 = STRREP(&TEXT1.LENGTH,&TEXT1,5,' car ',1,'~',&TEXT1.LENGTH,'A&TEXT1.LENGTH');


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Reply With QuoteReport This Post
Master
posted Hide Post
quote:
-SET &TEXT2 = STRREP(&TEXT1.LENGTH,&TEXT1,3,'car',1,'~',&TEXT1.LENGTH,'A&TEXT1.LENGTH');
-SET &TEXT3 = STRIP(&TEXT2.LENGTH,&TEXT2,'~','A&TEXT2.LENGTH');


Dan,
This is a good one. But I would prefer to replace with nothing instead of '~'. If my input string already contains '~', then here you go.

-SET &TEXT1      = 'this ~car that car ~those cars all have "scar~s"!';
-SET &SEARCH_STR = 'car';

-SET &TEXT2      = STRREP(&TEXT1.LENGTH,&TEXT1,&SEARCH_STR.LENGTH,&SEARCH_STR,0,'~',&TEXT1.LENGTH,'A&TEXT1.LENGTH');
-SET &TEXT2      = TRUNCATE(&TEXT2);
-SET &TEXT1_LEN  = ARGLEN(&TEXT1.LENGTH,&TEXT1,'I3');
-SET &TEXT2_LEN  = ARGLEN(&TEXT2.LENGTH,&TEXT2,'I3');

-SET &SEARCH_LEN = ARGLEN(&SEARCH_STR.LENGTH,&SEARCH_STR,'I3');

-SET &COUNTX     = (&TEXT1_LEN - &TEXT2_LEN) / &SEARCH_LEN ;

-TYPE &TEXT1
-TYPE &SEARCH_STR 
-TYPE &TEXT2
-TYPE &TEXT1_LEN
-TYPE &SEARCH_LEN
-TYPE &TEXT2_LEN
-TYPE &COUNTX
 
Posts: 542 | Location: Dearborn, MI | Registered: June 03, 2009Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You're absolutely right Ram. I tried this:

-SET &TEXT2 = STRREP(&TEXT1.LENGTH,&TEXT1,3,'car',0,'',&TEXT1.LENGTH,'A&TEXT1.LENGTH');

But it gave me an error message. It never occurred to me to just throw any character between the single quotes for the replacement string:

-SET &TEXT2 = STRREP(&TEXT1.LENGTH,&TEXT1,3,'car',0,'x',&TEXT1.LENGTH,'A&TEXT1.LENGTH');

But it works because the replacement string length is set to zero. Great job finding a "trick" that works.


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
Dan, that not good, its brilliant.

Next stop Mensa ?



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6104 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Thanks Waz. We all have our brilliant moments and our "what the Focus was I thinking" moments. But actually I think there was a similar post in the past year. I couldn't find it but I seemed to remembered the basic concept from that post. Cheers.


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
Well, no matter who had the idea, it is a brilliant piece of left field thinking.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6104 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
How to get multiple string variables from a parameter? [SOLVED] has an example of a DEFINE FUNCTION...


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, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
Oh dear, I had forgotten about that one, even posted against it.

Another senior moment!

As my son says, senior moment, another 5 minutes off your life.

Frowner


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6104 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Thanks to all!!
i will try the solutions. i build one by using the posit function.
-SET &SORTBY1=STRIP(60, &Sortfeld2, ' ', 'A60');
-SET &SORTBY=POSIT(&SORTBY1,60,'BY',2, I2);
-SET &ROUND1 = IF SORTBY1 GT '0' THEN '1' ELSE '0';
-SET &SORTBY2 = SUBSTR(60, &SORTBY1, &SORTBY + 1, 60, 50, A60);
-SET &SORTBY_1=POSIT(&SORTBY2,60,'BY',2, I2);
-SET &ROUND2 = IF &SORTBY_1 GT '0' THEN '1' ELSE '0';
-SET &SORTBY3 = SUBSTR(60, &SORTBY2, &SORTBY_1 + 1, 60, 50, A60);
-SET &SORTBY_2=POSIT(&SORTBY3,60,'BY',2, I2);
-SET &ROUND3 = IF &SORTBY_2 GT '0' THEN '1' ELSE '0';
-SET &SORTBY4 = SUBSTR(60, &SORTBY3, &SORTBY_2 + 1, 60, 50, A60);
at the end i counted the &ronds.
i think your solutions are much smarter but im just a beginner!!!

greetings

christian


WF Production Version: 7.7.02M
WF Test Version: 7.7.02M
Developer Studio: 7.7.02
HTML, EXL2K, FLEX, PDF,PPT
 
Posts: 156 | Location: Essen Germany | Registered: December 02, 2010Reply With QuoteReport This Post
Member
posted Hide Post
Can you use CONTAINS in a DEFINE?

DATA/A1 = IF str1 CONTAINS 'XYZ' THEN 'Y' ELSE 'N';
 
Posts: 29 | Location: Seattle Washington | Registered: July 08, 2009Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Find specific word in a string

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.