View previous topic :: View next topic
|
Author |
Message |
manigadu
New User
Joined: 29 Aug 2008 Posts: 10 Location: Bangalore
|
|
|
|
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 |
|
|
manigadu
New User
Joined: 29 Aug 2008 Posts: 10 Location: Bangalore
|
|
|
|
In the error, PARSE is my program name.. it is nothing to do with the parse function of rexx |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Code: |
commas = length(string) - length(space(translate(string, ' ', ','), 0)) |
|
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
COUNTSTR? Where did that come from? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
Back to top |
|
|
manigadu
New User
Joined: 29 Aug 2008 Posts: 10 Location: Bangalore
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
manigadu
New User
Joined: 29 Aug 2008 Posts: 10 Location: Bangalore
|
|
|
|
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)) |
|
COOL !!
Its working.. thanks a lot !! |
|
Back to top |
|
|
|