|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
newby question: vowels & consonants
Hi all,
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. Regards Rudi |
|
#2
|
|||
|
|||
|
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; begin 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 Else MyConVar := EditVar; end; |
|
#3
|
||||
|
||||
|
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.
Code:
procedure TForm1.Button1Click(Sender: TObject); var sIn : string; ch : char; begin sIn := Edit1.Text; ch := upcase(sIn[1]); if (ch in ['A', 'E', 'I', 'O', 'U']) then ShowMessage(sIn + ' starts with vowel') else ShowMessage(sIn + ' starts with consonant'); end;
__________________
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 Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > newby question: vowels & consonants |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|