Asp.net İki Sting karşılaştırma Compare Fonksiyonu

Asp.nette iki string ifadeyi karşılaştırmak için compare fonksiyonu kullanılır, compare fonksiyonu ile stirng ifadeleri karşılaştırırken küçük/büyük harf duyarlılık durumuna göre de ayarlama yapılabilir Küçük büyük harf duyarlıklık durumun da “string.Compare(ifade1,ifade2, false);” eğer küçük büyük harf fark etmez diyorsanız “string.Compare(ifade1,ifade2, true);” şeklinde kullnıyoruz.
stringcompare

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="aspnetornekleri.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2 style="color:Navy">asp.net string örnekleri: Compare() String Karşılaştırma</h2>  
        <asp:Label   
             ID="Label1"   
             runat="server"   
             Font-Size="Large"  
             ForeColor="HotPink"  
             Font-Bold="true"  
             Font-Italic="true"  
             >  
        </asp:Label>  
        <br /><br />  
        <asp:Label   
             ID="Label2"   
             runat="server"   
             Text="İfade 1"  
             ForeColor="DodgerBlue"  
             >  
        </asp:Label>  
        <asp:TextBox   
             ID="TextBox1"   
             runat="server"   
             BackColor="DodgerBlue"   
             ForeColor="Snow"  
             >  
        </asp:TextBox>  
        <br />  
        <asp:Label   
             ID="Label3"   
             runat="server"   
             Text="İfade 2"  
             ForeColor="DodgerBlue"  
             >  
        </asp:Label>  
        <asp:TextBox   
             ID="TextBox2"   
             runat="server"   
             BackColor="DodgerBlue"   
             ForeColor="Snow"  
             >  
        </asp:TextBox>  
        <br />
        <br />
        <asp:RadioButton ID="RadioButton1" runat="server" GroupName="kontrol" 
            Text="Küçük Büyük Harf Duyarlı" />
        <asp:RadioButton ID="RadioButton2" runat="server" GroupName="kontrol" 
            Text="Küçük Büyük Harf Duyarsız" />
        <br />  
        <asp:Button   
             ID="Button1"   
             runat="server"   
             OnClick="Button1_Click"  
             Font-Bold="true"  
             Text="Karşılaştır"  
             ForeColor="DodgerBlue"  
             />     
    </div>
    </form>
</body>
</html>

   protected void page_Load(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                TextBox1.Text = "Bilişim Öğretmeni";
                TextBox2.Text = "bilişim Öğretmeni";
            }
        }
        protected void Button1_Click(object sender, System.EventArgs e)
        {
            string ifade1 = TextBox1.Text.ToString();
            string ifade2 = TextBox2.Text.ToString();
            int result=0;
            if (RadioButton1.Checked)
            {
               result = string.Compare(ifade1,ifade2, false);
            }
            if (RadioButton2.Checked)
            {
                result = string.Compare(ifade1, ifade2, true);
            }

            Label1.Text = "";

            if (result == 0)
            {
                Label1.Text += "İfadeler Aynı..";
            }
            else 
            {
                Label1.Text += "İfadeler Farklı";
            }
            
        }  

You may also like...

Subscribe
Bildir
guest
0 Yorum
Inline Feedbacks
View all comments
0
Yazı hakkındaki yorum, görüş ve önerilerinizi yazınx
()
x