当前位置:编程学习 > C#/ASP.NET >>

如何比较字符串是忽略大小写?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
#region 吴新强于2013年4月10日10:55:03 桂电 2507
#endregion
namespace Compares
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 比较字符串是忽略大小写
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if(string.Compare(textBox1 .Text .ToLower (),textBox2.Text.ToLower())<0)
            MessageBox.Show ("字符串1小于字符串2","信息",MessageBoxButtons.OK,MessageBoxIcon.Information );

            if (string.Compare(textBox1.Text.ToLower(), textBox2.Text.ToLower()) == 0)
                MessageBox.Show("字符串1等于字符串2", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (string.Compare(textBox1.Text.ToLower(), textBox2.Text.ToLower()) > 0)
                MessageBox.Show("字符串1大于字符串2", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}


 

 

\

 

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,