Comparing strings
-
Hello, I'm a real rookie so pls don't laugh ... How do I compare 2 strings ? I have this code: var strPassword=Request.Form("pass"); var strSQLQuery="SELECT * FROM clienti WHERE user_name=\'"+strUserName+"\'"; rc=conn.Execute(strSQLQuery); if (rc.eof) {Response.Write("User or password incorrect");} else { if ( rc.Fields("password") == strPassword) { Response.Write("Welcome"); } else { Response.Write("User or password incorrect"); Response.Write(strUserName+strPassword); Response.Write(rc.Fields("user_name")+rc.Fields("password")); } } Can anyone please enlighten me why it never enters the "if ( tempPass == strPassword)" even thought when it enters the second else it shows the strings to be identical ?
-
Hello, I'm a real rookie so pls don't laugh ... How do I compare 2 strings ? I have this code: var strPassword=Request.Form("pass"); var strSQLQuery="SELECT * FROM clienti WHERE user_name=\'"+strUserName+"\'"; rc=conn.Execute(strSQLQuery); if (rc.eof) {Response.Write("User or password incorrect");} else { if ( rc.Fields("password") == strPassword) { Response.Write("Welcome"); } else { Response.Write("User or password incorrect"); Response.Write(strUserName+strPassword); Response.Write(rc.Fields("user_name")+rc.Fields("password")); } } Can anyone please enlighten me why it never enters the "if ( tempPass == strPassword)" even thought when it enters the second else it shows the strings to be identical ?
You should take a look at the documentation for
String.Equals
andString.Compare
, the latter allowing you to compare strings in a case-insensitive manner. It can optionally take a culture into account, too.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Hello, I'm a real rookie so pls don't laugh ... How do I compare 2 strings ? I have this code: var strPassword=Request.Form("pass"); var strSQLQuery="SELECT * FROM clienti WHERE user_name=\'"+strUserName+"\'"; rc=conn.Execute(strSQLQuery); if (rc.eof) {Response.Write("User or password incorrect");} else { if ( rc.Fields("password") == strPassword) { Response.Write("Welcome"); } else { Response.Write("User or password incorrect"); Response.Write(strUserName+strPassword); Response.Write(rc.Fields("user_name")+rc.Fields("password")); } } Can anyone please enlighten me why it never enters the "if ( tempPass == strPassword)" even thought when it enters the second else it shows the strings to be identical ?
AS Heath mentions, try the built in string comparison methods. Another tip in string manip;
Trim
. It will save much hair tearing. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?