View previous topic :: View next topic
|
Author |
Message |
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Move your variable into (temp) table and use a perform loop statement. This should do the trick with one if condition. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Try following loop. Improvements welcome!
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.
Code: |
INSPECT STR TALLYING VOV-CNT FOR ALL 'A' , 'a', 'E', 'e', 'I', 'i', 'O', 'o' ,'u','U' |
|
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Correction:
Please read STR(I) as STR(I:1) |
|
Back to top |
|
|
wicked1925
New User
Joined: 12 Mar 2007 Posts: 15 Location: Philippines
|
|
|
|
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 |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Thanks for getting back.
Good luck |
|
Back to top |
|
|
|