c# - How to check whether a string starts with vowel

String starts with vowel
string-starts-with-vowel.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html>  
<script runat="server"> 
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        //this section create string variables.
        string stringPlants = "Thimbleweed. Tassel Weed. Sweet Potato.";
        string stringPlants2 = "Orange Coneflower. Yellow Corydalis. White Tansy.";

        Label1.Text = "string of plants..................<br />";
        Label1.Text += stringPlants;
        Label1.Text += "<br />"+stringPlants2;

        //this line create a char array.
        char[] vowels = { 'a', 'e', 'i', 'o', 'u' };

        //this line get string first/begin character (lower case)
        char firstCharacter = stringPlants.ToLower().ToCharArray().ElementAt(0);

        //this line get string first/begin character (lower case)
        char firstCharacter2 = stringPlants2.ToLower().ToCharArray().ElementAt(0);

        //test string starts with vowel or not
        Boolean result = vowels.Contains(firstCharacter);
        Boolean result2 = vowels.Contains(firstCharacter2);

        Label1.Text += "<br /><br />stringPlants first character: " + firstCharacter;
        Label1.Text += "<br />stringPlants2 first character: " + firstCharacter2;

        Label1.Text += "<br /><br />stringPlants starts with vowel? " + result.ToString();
        Label1.Text += "<br />stringPlants2 starts with vowel? " + result2.ToString();
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - string starts with vowel</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:MidnightBlue; font-style:italic;">  
            c# example - string starts with vowel
        </h2>  
        <hr width="550" align="left" color="Gainsboro" />  
        <asp:Label   
            ID="Label1"   
            runat="server"  
            Font-Size="Large"
            >  
        </asp:Label>  
        <br /><br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="string starts with vowel"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples