Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to count number of occurrences of string1 in string2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
manigadu

New User


Joined: 29 Aug 2008
Posts: 10
Location: Bangalore

PostPosted: Thu Sep 30, 2010 9:38 pm    Post subject: How to count number of occurrences of string1 in string2
Reply with quote

I am new to rexx.. please help me
Example:
String1: ','
String2: 'apple,ball,cat,dog'

Now I want to count the number of ',' and hence I can find the number of names that are entered in string2.

I tried countstr(string1,string2).
But am getting an error saying:
Error running PARSE, line 3: Unexpected "," or ")"
Back to top
View user's profile Send private message

manigadu

New User


Joined: 29 Aug 2008
Posts: 10
Location: Bangalore

PostPosted: Thu Sep 30, 2010 9:49 pm    Post subject: Reply to: How to count number of occurrences of string1 in s
Reply with quote

In the error, PARSE is my program name.. it is nothing to do with the parse function of rexx
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1060
Location: Oostende, Belgium

PostPosted: Thu Sep 30, 2010 9:52 pm    Post subject:
Reply with quote

Code:
commas = length(string) - length(space(translate(string, ' ', ','), 0))
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4650
Location: Raleigh, NC, USA

PostPosted: Thu Sep 30, 2010 10:47 pm    Post subject: Reply to: How to count number of occurrences of string1 in s
Reply with quote

COUNTSTR? Where did that come from?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Thu Sep 30, 2010 11:08 pm    Post subject: Where does Countstr come from?
Reply with quote

superk wrote:
COUNTSTR? Where did that come from?


Reginald Rexx for the PC

http://home.roadrunner.com/~jgglatt/rexx/faq/faq.htm
http://home.roadrunner.com/~jgglatt/rexx/win32/rxusrw32.htm
http://software.informer.com/getfree-reginald-rexx-interpreter/
Back to top
View user's profile Send private message
manigadu

New User


Joined: 29 Aug 2008
Posts: 10
Location: Bangalore

PostPosted: Fri Oct 01, 2010 12:15 am    Post subject:
Reply with quote

prino wrote:
Code:
commas = length(string) - length(space(translate(string, ' ', ','), 0))


thanks for the code... it is working.. but

if I have the string like "apple ball,cat" I should get the count of commas as 1.. but as per your code.. it gives me the count of commas as 2. Because we are counting the number of spaces.. by translating the commas to spaces..
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1060
Location: Oostende, Belgium

PostPosted: Fri Oct 01, 2010 12:18 am    Post subject:
Reply with quote

manigadu wrote:
prino wrote:
Code:
commas = length(string) - length(space(translate(string, ' ', ','), 0))


thanks for the code... it is working.. but

if I have the string like "apple ball,cat" I should get the count of commas as 1.. but as per your code.. it gives me the count of commas as 2. Because we are counting the number of spaces.. by translating the commas to spaces..


So Mrs Lincoln, how was the play?

Code:
commas = length(space(string, 0)) - length(space(translate(string, ' ', ','), 0))
Back to top
View user's profile Send private message
manigadu

New User


Joined: 29 Aug 2008
Posts: 10
Location: Bangalore

PostPosted: Fri Oct 01, 2010 2:20 am    Post subject:
Reply with quote

prino wrote:
manigadu wrote:
prino wrote:
Code:
commas = length(string) - length(space(translate(string, ' ', ','), 0))


thanks for the code... it is working.. but

if I have the string like "apple ball,cat" I should get the count of commas as 1.. but as per your code.. it gives me the count of commas as 2. Because we are counting the number of spaces.. by translating the commas to spaces..


So Mrs Lincoln, how was the play?

Code:
commas = length(space(string, 0)) - length(space(translate(string, ' ', ','), 0))


icon_biggrin.gif COOL !!

Its working.. thanks a lot !!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to write Rexx program to size and... sreejeshcs CLIST & REXX 14 Thu Oct 12, 2017 7:26 am
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts SORT Trailer Count - LRECL Output co... amorante DFSORT/ICETOOL 5 Tue Aug 29, 2017 8:57 pm
No new posts Profile changed to NUMBER ON STD (fro... Martylin TSO/ISPF 1 Thu Aug 03, 2017 9:14 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us