Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Comparing strings

Comparing strings

Scheduled Pinned Locked Moved ASP.NET
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlackRider
    wrote on last edited by
    #1

    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 ?

    H P 2 Replies Last reply
    0
    • B BlackRider

      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 ?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You should take a look at the documentation for String.Equals and String.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-----

      1 Reply Last reply
      0
      • B BlackRider

        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 ?

        P Offline
        P Offline
        Paul Watson
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups