#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    28
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    North Yorkshire (U.K.)
    Posts
    64
    Rep Power
    14
    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;
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo