本文介绍了如何检查两个字符串是否相同...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string val1="prince";<br />
string val2="PRINCE";



如何检查两个字符串值是否相等,如果相等,则必须显示一个Confirm box,味精Do u Want to Continue?,否则,如果两个字符串不同,则确认味精为The Two value are different, Do u want to Continue? ,我还需要将这些值保存到数据库.

问候
Prince Antony G



How to check two string values are equal and if its equal then one Confirm box must be displayed,the msg Do u Want to Continue?, or otherwise if the two string are different then confirm msg be The Two value are different, Do u want to Continue? also i need to save those value into Database.

Regards
Prince Antony G

推荐答案

if(val1.Equals(val2, StringComparison.InvariantCultureIgnoreCase))
{
   // they are the same
}




要显示asp.net对话框,请参见此处: http://www.4guysfromrolla.com/articles/021104-1.aspx [ ^ ]



EDIT :
To show asp.net dialogs see here : http://www.4guysfromrolla.com/articles/021104-1.aspx[^]


protected void Button1_Click(object sender, EventArgs e)
{
   int comp = string.Compare(TextBox1.Text, TextBox2.Text, false);
// true - for case insensitive/ ignore case 
// false - for case sensitive 

        if (comp == 0) // If values are same
        {   
            Response.Write("<script>confirm('The Two Value Are Same. Do you Want to Continue?');</script>");
        }

        else   // If values are different
        {          
            Response.Write("<script>confirm('The Two value are different, Do you  want to Continue?');</script>");
        }
   
}


int result = string.Compare(val1, val2,true);


        if(result == 0)
        {
//Strings are equal

          }


这篇关于如何检查两个字符串是否相同...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 06:35