Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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

Active Member


Joined: 07 Feb 2009
Posts: 989
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: 4648
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: 6966
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

Active Member


Joined: 07 Feb 2009
Posts: 989
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 abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Sequence number add in SORT pshongal SYNCSORT 3 Fri Sep 02, 2016 3:32 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
No new posts GDG vsersion number change Raghu navaikulam JCL & VSAM 5 Fri May 27, 2016 4:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us