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
 

 

Count the number of vowels present in an input string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Count the number of vowels present in an input string
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: 1439
Location: Bangalore,India

PostPosted: Tue Mar 20, 2007 2:39 pm    Post subject:
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: 685
Location: Earth

PostPosted: Tue Mar 20, 2007 2:59 pm    Post subject:
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: 685
Location: Earth

PostPosted: Tue Mar 20, 2007 3:01 pm    Post subject:
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    Post subject:
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: 2360
Location: Israel

PostPosted: Tue Mar 20, 2007 4:14 pm    Post subject:
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: 685
Location: Earth

PostPosted: Tue Mar 20, 2007 4:43 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 15 Thu Dec 01, 2016 8:28 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
This topic is locked: you cannot edit posts or make replies. How to use 2 input files in control c... Gunapala CN DFSORT/ICETOOL 23 Thu Oct 13, 2016 3:42 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


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