April 29th, 2004, 07:30 AM
newby question: vowels & consonants
I need to take the value from an editbox and be able to identify the words start with vowels and but them into a var and words that start with consonants into and other vowel.
Any ideas of how to go about this?
Any help will be much appreciated.
April 29th, 2004, 01:04 PM
This is a clumsy way, utilising arrays would probably be better, but until you learn how to use them or somebody is happy to show you, this should do the trick.
procedure TForm1.Btn1Click(Sender: TObject);
Var EditVar, MyConVar, MyVowelVar : String;
EditVar := Copy( UpperCase( Edit1.Text ), 1, 1 );
If ( Pos( 'A', EditVar ) = 1 ) or
( Pos( 'E', EditVar ) = 1 ) or
( Pos( 'I', EditVar ) = 1 ) or
( Pos( 'O', EditVar ) = 1 ) or
( Pos( 'U', EditVar ) = 1 ) Then
MyVowelVar := EditVar
MyConVar := EditVar;
April 29th, 2004, 04:58 PM
Another way is to use Pascal's set operator to see if a character is within a set of characters or not. Incidentally, you can refer to a single character in a string by its index, instead of using Copy.
procedure TForm1.Button1Click(Sender: TObject);
sIn : string;
ch : char;
sIn := Edit1.Text;
ch := upcase(sIn);
if (ch in ['A', 'E', 'I', 'O', 'U']) then
ShowMessage(sIn + ' starts with vowel')
ShowMessage(sIn + ' starts with consonant');
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo