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

Count the number of vowels present in an input string


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Tue Mar 20, 2007 2:31 pm
Reply with quote

hi guys,

i want to count the number of vowels present in an input string, lets say max length of 50. can you give me suggestions on how to do this without overdoing the EVALUATE statement?

thanks in advance...
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 2:39 pm
Reply with quote

Move your variable into (temp) table and use a perform loop statement. This should do the trick with one if condition.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Mar 20, 2007 2:59 pm
Reply with quote

Try following loop. Improvements welcome! icon_smile.gif
Code:
  MOVE 0 TO VAV-CNT
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 50
    IF STR(I) = 'A' OR 'a' OR 'E' OR 'e' OR 'I' OR 'i' OR 'O' OR 'o' OR 'u' OR 'U'
    ADD 1 TO VOV-CNT
    END-IF
  END-PERFORM
  DISPLAY VOV-CNT

or you can use INSPECT verb- (Do check the manual for INSPECT , because I am not sure about the syntax here. icon_smile.gif

Code:
  INSPECT STR TALLYING VOV-CNT FOR ALL 'A' , 'a', 'E', 'e', 'I', 'i', 'O', 'o' ,'u','U'
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Mar 20, 2007 3:01 pm
Reply with quote

Correction:
Please read STR(I) as STR(I:1) icon_redface.gif
Back to top
View user's profile Send private message
wicked1925

New User


Joined: 12 Mar 2007
Posts: 15
Location: Philippines

PostPosted: Tue Mar 20, 2007 3:22 pm
Reply with quote

thanks guys...

all the suggestions worked perfectly...oh btw the inspect clause is correct and i think i'm gonna use that for my final code. thanks again.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Tue Mar 20, 2007 4:14 pm
Reply with quote

I know you asked for COBOL, but just for the fun, here is a REXX example:
Code:
/* REXX */                                                             
                                                                       
A        = 'THIS IS AN EXAMPLE OF VOWEL COUNTING REXX'                 
NO_VOWEL = 'BCDFGHJKLMNPQRSTVWXYZ1234567890'                           
B        = LENGTH(STRIP(SPACE(TRANSLATE(A,' ',NO_VOWEL),0)))           
SAY B                                                                   
                                                                       
EXIT                                                                   
                                                                       


O.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Tue Mar 20, 2007 4:43 pm
Reply with quote

Thanks for getting back.
Good luck icon_biggrin.gif
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts To get the count of rows for every 1 ... DB2 3
Search our Forums:

Back to Top