IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to count number of occurrences of string1 in string2


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
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
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
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: 1306
Location: Vilnius, Lithuania

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

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

Global Moderator


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

PostPosted: Thu Sep 30, 2010 10:47 pm
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: 6966
Location: porcelain throne

PostPosted: Thu Sep 30, 2010 11:08 pm
Reply with quote

superk wrote:
COUNTSTR? Where did that come from?


Reginald Rexx for the PC

home.roadrunner.com/~jgglatt/rexx/faq/faq.htm
home.roadrunner.com/~jgglatt/rexx/win32/rxusrw32.htm
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
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: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Oct 01, 2010 12:18 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top