Link to home
Start Free TrialLog in
Avatar of Ricky11
Ricky11

asked on

How to compare two string with " in the string?

I have two stringed varaibles.

A = 72X90"OB
B = 72X90"OB

I could easily do this
A = 72X90"OB
B = 72X90"OB

than a would = to be, that is fine, but my strings are from my database fields,
so for example if rs.("size") = 72X90"OB,  and rs.("size2") = 72X108"OB
and if i comapre RS.("SIZE") WITH RS("SIZE2") it wont work. even if i assisgn variables to both the records.

so what i think i have to do is firstly replace the " with &quote; as so
a = rs.("size")
a = Replace(a,""", """)%>

however it comes back with a error when i load the page as such.
Microsoft VBScript compilation error '800a03ee'

Expected ')'

/asp/tablecloth2.asp, line 381

a = Replace(a,""", """)
-------------------------------^
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to keep the actual quotation mark in, this should work:

= Replace(a,"""", """""")
Avatar of sybe
sybe

You have to compare the values, not the fields:

If  RS.("SIZE").Value = RS("SIZE2").Value Then

Else

End If

If you leave out the "Value"  property, then it's the fields that are being compared, and the fields are different (just because they have a different name)
or change this

if rs.("size") = 72X90"OB,  and rs.("size2") = 72X108"OB

to this

if rs("size") = 72X90"OB,  and rs("size2") = 72X108"OB

HTH..

HAppy programming

just take the . soemthing like this

if rs("size") = 72X90"OB

if rs("size2") = 72X108"OB

or

if rs("size") = 72X90"OB  AND rs("size2") = 72X108"OB

HTH...

HAppy programming
replacing the double quote by using the ascii-code of the sign should do the work.

try this:

a = rs.("size")
a = Replace(a,chr(34), """)

good luck!
Using AND,  both should be equal to size.  If one of them is enough,  then you should use or.

Why are you using the " in the value 72x108"OB?

hhammash
I suspect that the " is for inches.

FtB
Avatar of Ricky11

ASKER

I have concluded that comapring variables that contain the " chr inside the string itself is impossible, asp will not be able to sucsessfully comapre them.. I have tried to replace the " with the ascii chrs, with " and then comparing them but still no luck.

For example
A = 72X90"OB
B = 72X90"OB

If asked to compare a to b it will return false.

So what I have decided to to is to REPLACE the " from the string after requesting it as ftb suggested.

I have sucsessfully replaced A from 72X90"OB to 72X90B, note that A is the querystring which is reqested from the URL parameter.

Now B is the problem is doesn't seem to want to replace it for some reason, it doesn't return a error, note that B is a a record from the field in the database.

My code as follows and below the code is the output in IE/

<%t = 1 %>
<%a = Request.QueryString("firstofsize")%><br>
OLD A IS, <%=A%><br>
<%a = Replace(a,"""","")%>
NEW A IS, <%=A%>
<BR><br>
<%For t = 1 to 6 %>
<% b = FP_FieldVal(fp_rs,"size" & t) %> ' SIZE1, SIZE, SIZE3 are from the database
OLD B IS <%=b%><br>
<%b = Replace(b,"""", "")%>
NEW B IS <%=b%><br>

 If a = b Then
     Response.write "*FOUND*"
  Else
    response.write " NOT FOUND "
  End If
Next%>

THIS IS THE OUTPUT
A IS, 72X90"OB
NEW A IS, 72X90OB '- correctly changed

OLD B IS 36X36"RD
NEW B IS 36X36"RD '- not changed at all

' THUS A CANNOT EQUAL TO B IF B IS NOT BEING REPLACED SUCSESSFULLY, any ideas why?

Tks.


Avatar of Ricky11

ASKER

Also for B if i replace for example <%b = Replace(b,"72", "XX")%>

It will replce it then, so the output will be form 72X90"OB TO XXX90"OB

Stange that for B it will replace the other chrs but not the quotation as it did sucsessfullly in A.

Hope this is not too confusing.
Avatar of Ricky11

ASKER

SOLVED.

For some reason for the querystring (a) it was able to replace it just by using
<%a = Replace(a,"""","")%>

however for B since it was a record in a database i was unable to use the same method, it probabaly coun't find the "  inside the field for some reason, even though it was there, so i change it to this.

<%b = Replace(b,"&quot;","")%>

and then it sucsessfully change it from 72X90"OB to 72X90OB
and found the correct record.

however if i apply the same code used to replace b for A, it wouldn't work, i.e. if i did
<% a= Replace(a,"&quot;","")%> the output would still be 72X90"OB strange the way it works differently for querystrings and for database records.

Anyway. Thank for your help FTB.
Glad to have helped and good luck,

FtB