Tech Tip: Determining if character in a string is a vowel
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: May 27, 2015
Below is an utility method to determine if a character in a string is a vowel. Vowels are the characters a,e,i,o,u and sometimes y.
//Method name: isVowel //Determines if character specified in string is a vowel //$1 - source string //$2 - position of string for the character to check //$0 - True if a constant, false if not C_TEXT($1;$string) //source string C_LONGINT($2;$i) //position of string to check C_TEXT($char) C_LONGINT($l) C_BOOLEAN($0;$isVowel) If (Count parameters>=2) $string:=$1 $i:=$2 $l:=Length($string) If ($i<=$l) & ($i>0) $char:=$string[[$i]] Case of : ($char="a")|($char="e")|($char="i")|($char="o") | ($char="u") //vowels $isVowel:=True : ($char="y") //check to see if y is a vowel or a constant If ($i=1) //if y is the first character, y is a constant $isVowel:=False Else If ($i<($l+1)) $isVowel:=Not(isVowel ($string;$i-1)) //if char before y is a const, y //is a vowel; else y is a constant Else $isVowel:=False End if End if Else $isVowel:=False End case End if $0:=$isVowel End if |
Example:
$string:="apple" $isVowel:=isVowel($string;1) //returns true $isVowel:=isVowel($string;2) //returns false $string:="yak" $isVowel:=isVowel($string;1) //returns false $string:="myth" $isVowel:=isVowel($string;2)//returns true |
Commented by Keith Culotta on June 4, 2015 at 10:13 AM
Consonant