?
Solved

Comparing two strings

Posted on 2005-03-27
6
Medium Priority
?
401 Views
Last Modified: 2007-12-19
hi experts

I have the following code to compare two string
in fact i have two strings stored in the db
one is encrypted, the other is not encrypted

i am comparing decrypted value of the encrypted one with the other string and display a message accordingly

Sub ValidateCoupon (rc, msg)
dim EncodedName, DecodedName, Realname
EncodedName=couponname
DecodedName= Base64decode(EncodedName)
Realname = couponother

response.write "realname = <br>" & DecodedName & "<br>"
response.write "couponother = <br>" & Realname

if ucase(DecodedName) <> ucase(Realname) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
end sub

OK now my problem it that when i compare decodedname and realname,
i get the result  "Bad coupon name" even if they are equal

My response.write shows that decodedname and realname are the same.

What the problem ?
Thx


0
Comment
Question by:humer2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 13641464
Do this:

<%
response.write "realname = <br>|" & DecodedName & "|<br>"
response.write "couponother = <br>|" & Realname & "|<br>
%>

I'm guessing there's some blank spaces in there
0
 
LVL 31

Accepted Solution

by:
alorentz earned 2000 total points
ID: 13641468
Also try this:

<%
if ucase(trim(DecodedName)) <> ucase(trim(Realname)) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
%>
0
 
LVL 31

Expert Comment

by:alorentz
ID: 13641508
Could also do this:

<%
if ucase(left(DecodedName, len(realname))) <> ucase(Realname) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
%>

Maybe return carriage or line feed on end of decode name, so just take the length of the realname and compare.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:calvinfoo
ID: 13641674
Hi,

 try this:

  if ucase(trim(DecodedName)) <> ucase(trim(Realname)) then
     msg= "Bad coupon name"
     rc=4
     exit sub
end if
0
 
LVL 1

Expert Comment

by:calvinfoo
ID: 13641679
ops, sorry, I guess I've repeated what alorentz said.
0
 
LVL 2

Expert Comment

by:Sukamal_Sengupta
ID: 13642115
Hi humer2000,

Hope the string that you get after decrypte the string (which is store in the db) is done correctly means there is no any hidden word or space included into that string, which is not shown in the browser.
 
Try the following code which is slightly modified from your code,

Sub ValidateCoupon (rc, msg)
    dim EncodedName, DecodedName, Realname
    EncodedName=couponname
    DecodedName= Base64decode(EncodedName)
    Realname = couponother

   DecodedName = Trim(cstr(DecodedName))
   Realname = Trim(cstr(Realname ))

   response.write "DecodedName = <br>" & DecodedName & "<br>"
   response.write "Realname = <br>" & Realname

  if ((cstr(DecodedName)) <>(cstr(Realname))) then
     msg= "Bad coupon name"
     rc=4
     exit sub
  end if

end sub


Hope you don't use the procedure i.e., ValidateCoupon within any loop.

Try the Modified code. Hope your problem will be solved.

Thanks,
Sukamal Sengupta


 
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question