C#不区分字母大小写比较字符串

时间:2021-06-14 00:58:14

        private void button11_Click(object sender, EventArgs e)
        {//不区分字母大小写比较字符串
            String MyStrA="Microsoft ";
            String MyStrB="MicroSoft ";
            String MyInfo="";
            MyInfo+="\n不分区字母大小写比较"+MyStrA+"和"+MyStrB+"是";
            if(String.Compare(MyStrA,MyStrB,true)==0)
                MyInfo+="相同的!";
            else
                MyInfo+="不同的";
            MessageBox.Show(MyInfo , "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            MyInfo = "";
            MyInfo += "\n分区字母大小写比较" + MyStrA + "和" + MyStrB + "是";
           // if (String.Compare(MyStrA, MyStrB,false) == 0)
            if (String.Compare(MyStrA, MyStrB) == 0)
                MyInfo += "相同的!";
            else
                MyInfo += "不同的";
            MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }