1. Compare question

This is a multi-part message in MIME format.

------=_NextPart_000_001D_01C37F91.9FDE7E50
	charset="iso-8859-1"

I am trying to compare a value first position in a html file. This =
position contains "<"    with a this next line of code
 This is supposed to be an equal compare for the very first position
 =3D=3D> if compare( "<", line[i]) =3D 0 and
     compare(line[i+1], "t") =3D 0 and=20
        compare(line[i+2], "d") =3D 0 =20
      then
     puts(1, line)   -- output is:  ABC

Jim

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
code follows
sequence buffer
object line
integer fn
trace(1)
-- read a text file into a sequence
fn =3D open("te.html", "r")
if fn =3D -1 then
 puts(1, "Couldn't open myfile.txt\n")
 abort(1)
end if

buffer =3D {}
while 1 do
 line =3D gets(fn)
 for i =3D 1 to length(line) do
  printf(1, "%s", {line[i]})   -- correct
   puts(1, line[i])
    puts(1, lessThan)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
  if compare( "<", line[i]) =3D 0 and
     compare(line[i+1], "t") =3D 0 and=20
        compare(line[i+2], "d") =3D 0 =20
      then
     puts(1, line)   -- output is:  ABC
     buffer =3D append(buffer, line)=20
  end if
=20
 if atom(line) then
  exit   -- -1 is returned at end of file
 end if
 end for
  puts(1, line)   -- output is:  ABC

=20
end while
exit

------=_NextPart_000_001D_01C37F91.9FDE7E50
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2730.1700" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to compare a value first =
position in a=20
html file. This position contains "&lt;"&nbsp; &nbsp; with a this next =
line of=20
code</FONT></DIV>
<DIV>&nbsp;<FONT face=3DArial size=3D2>This is supposed to be an equal =
compare for=20
the very first position</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;=3D=3D&gt; if compare( "&lt;", =
line[i]) =3D 0=20
and<BR>&nbsp;&nbsp;&nbsp;&nbsp; compare(line[i+1], "t") =3D 0 and=20
<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; compare(line[i+2], "d") =3D =
0&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts(1,=20
line)&nbsp;&nbsp; -- output is:&nbsp; ABC</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jim</FONT></DIV>
<DIV><BR><FONT face=3DArial =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FO=
NT></DIV>
<DIV><FONT face=3DArial size=3D2>code follows</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>sequence buffer<BR>object =
line<BR>integer=20
fn<BR>trace(1)<BR>-- read a text file into a sequence<BR>fn =3D =
open("te.html",=20
"r")<BR>if fn =3D -1 then<BR>&nbsp;puts(1, "Couldn't open=20
myfile.txt\n")<BR>&nbsp;abort(1)<BR>end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>buffer =3D {}<BR>while 1 =
do<BR>&nbsp;line =3D=20
gets(fn)<BR>&nbsp;for i =3D 1 to length(line) =
do<BR>&nbsp;&nbsp;printf(1, "%s",=20
{line[i]})&nbsp;&nbsp; -- correct<BR>&nbsp;&nbsp;&nbsp;puts(1,=20
line[i])<BR>&nbsp;&nbsp;&nbsp;&nbsp;puts(1, lessThan)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<BR>&nbsp;&nbsp;if=20
compare( "&lt;", line[i]) =3D 0 and<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
compare(line[i+1],=20
"t") =3D 0 and <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
compare(line[i+2], "d") =3D=20
0&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts(1, line)&nbsp;&nbsp; -- =
output=20
is:&nbsp; ABC<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer =3D append(buffer, =
line)=20
<BR>&nbsp;&nbsp;end if<BR>&nbsp;<BR>&nbsp;if atom(line)=20
then<BR>&nbsp;&nbsp;exit&nbsp;&nbsp; -- -1 is returned at end of=20
file<BR>&nbsp;end if<BR>&nbsp;end for<BR>&nbsp;&nbsp;puts(1, =
line)&nbsp;&nbsp;=20
-- output is:&nbsp; ABC</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>end=20

------=_NextPart_000_001D_01C37F91.9FDE7E50--

new topic     » topic index » view message » categorize

2. Re: Compare question

On Sat, 20 Sep 2003 16:09:52 -0600, sixs at ida.net wrote:

>
>I am trying to compare a value first position in a html file. This =
position contains "<"    with a this next line of code
> This is supposed to be an equal compare for the very first position
> =3D=3D> if compare( "<", line[i]) =3D 0 and
try compare('<',line[i]).

line is going to be "<td.., so line[1] is a character, not a string.
You don't need compare in this case, using line[i]=3D'<' is fine.

Pete

new topic     » goto parent     » topic index » view message » categorize

3. Re: Compare question

Lucius L. Hilley III
----- Original Message ----- 
From: "Pete Lomax" <petelomax at blueyonder.co.uk>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Compare question


>
>
> On Sat, 20 Sep 2003 16:09:52 -0600, sixs at ida.net wrote:
>
> >
> >I am trying to compare a value first position in a html file. This
position contains "<"    with a this next line of code
> > This is supposed to be an equal compare for the very first position
> > ==> if compare( "<", line[i]) = 0 and
> try compare('<',line[i]).
>
> line is going to be "<td.., so line[1] is a character, not a string.
> You don't need compare in this case, using line[i]='<' is fine.
>
> Pete
>

And to expand on that.
Correcting your code becomes:
if compare( '<', line[i]) = 0 and
     compare(line[i+1], 't') = 0 and
        compare(line[i+2], 'd') = 0
      then
     puts(1, line)   -- output is:  ABC

and is the same as:

if compare(">td", line[i..i+2]) = 0 then
  puts(1, line) -- output is: ABC
end if

You can also use: equal(">td", line[i..i+2])

        Lucius L. Hilley III - Unkmar
        Senior EXaminer - SEX <big grin>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu