MODULE CountChars5; (* ========================================================================= Example GPCP .NET Console Program Count the number of occurrences of different categories of characters in a string using a CASE statement Author : Chris Burrows Created: Jan 2007 (c) 2007-2008 CFB Software http://www.cfbsoftware.com/gpcp ========================================================================= *) IMPORT Out, CPmain; PROCEDURE WriteCount(count: INTEGER; IN msg: ARRAY OF CHAR); BEGIN Out.Int(count, 3); Out.String(msg); Out.Ln() END WriteCount; PROCEDURE CountChars(IN s: ARRAY OF CHAR); VAR i, vowels, letters, capitals, digits, others: INTEGER; BEGIN Out.String(s); Out.Ln(); vowels := 0; letters := 0; capitals := 0; digits := 0; others := 0; FOR i := 0 TO LEN(s$) - 1 DO CASE s[i] OF 'a', 'e', 'i', 'o', 'u': INC(vowels); INC(letters) | 'A', 'E', 'I', 'O', 'U': INC(vowels); INC(letters); INC(capitals) | 'b'..'d', 'f'..'h', 'j'..'n', 'p'..'t', 'v'..'z': INC(letters) | 'B'..'D', 'F'..'H', 'J'..'N', 'P'..'T', 'V'..'Z': INC(letters); INC(capitals) | '0'..'9': INC(digits) ELSE INC(others) END END; WriteCount(letters, ' letters'); WriteCount(capitals, ' capitals'); WriteCount(vowels, ' vowels'); WriteCount(letters - vowels, ' consonants'); WriteCount(digits, ' digits'); WriteCount(others, ' others'); Out.Ln() END CountChars; BEGIN CountChars('The quick brown fox jumped over the lazy dog.'); CountChars('Digit 1 looks like letter l, and digit 0 looks like letter O.') END CountChars5.