Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28827 > unrolled thread

string comparison fails? - Image1.jpg (0/1)

Started byjoe <mt@invalid.com>
First post2015-10-17 13:00 +0300
Last post2015-10-17 12:28 +0200
Articles 8 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  string comparison fails? - Image1.jpg (0/1) joe <mt@invalid.com> - 2015-10-17 13:00 +0300
    Re: string comparison fails? - Image1.jpg (0/1) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-17 11:18 +0100
      Re: string comparison fails? - Image1.jpg (0/1) joe <mt@invalid.com> - 2015-10-17 13:57 +0300
      Re: string comparison fails? - Image1.jpg (0/1) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-17 14:59 +0200
        Re: string comparison fails? - Image1.jpg (0/1) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-17 14:37 +0100
          Re: string comparison fails? - Image1.jpg (0/1) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-17 16:11 +0200
    Re: string comparison fails? - Image1.jpg (0/1) "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-10-17 12:21 +0200
    Re: string comparison fails? - Image1.jpg (0/1) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-17 12:28 +0200

#28827 — string comparison fails? - Image1.jpg (0/1)

Fromjoe <mt@invalid.com>
Date2015-10-17 13:00 +0300
Subjectstring comparison fails? - Image1.jpg (0/1)
Message-ID<08642bl9537lanf90ghcng1hefvuejcl20@4ax.com>
In my javascript I use XMLHttpRequest to get an htm file into text memory
(varaibale "all") and them split the text into an array with following code:

...
            var apu2=all.split(">");
            var ii=apu2.length;
            for (i=0;i<ii;i++)
               {
               allte=apu2[i].substring(0,4);
               if (allte=="TTY")
                  {
...

I then have apu2 as:
apu2[0]  "-><!DOCTYPE.."
apu2[1]  "<HTML"
..
apu2[8]  "TTYAhelpc.htm"
..

(I've include a small jpg to illustrate it)

When cycling through the string and "allte" variable gets "TTY" the comparison 
if (allte=="TTY")
fails allthough I can clearly see in debugger that is has "TTY" (see my jpg
image).

What I am doing wrong? I tried everything I could think of.

The local file I'me reading into "all" and then splitting into array at ">" is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<BODY>
TTY:helpc.htm
</body>
</html>

[toc] | [next] | [standalone]


#28829

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-17 11:18 +0100
Message-ID<87io65pzlw.fsf@bsb.me.uk>
In reply to#28827
joe <mt@invalid.com> writes:

> In my javascript I use XMLHttpRequest to get an htm file into text memory
> (varaibale "all") and them split the text into an array with following code:
>
> ...
>             var apu2=all.split(">");
>             var ii=apu2.length;
>             for (i=0;i<ii;i++)
>                {
>                allte=apu2[i].substring(0,4);
>                if (allte=="TTY")

There's a big clue here.  How can a 4 character string ever equal "TTY"?

<snip>
> The local file I'me reading into "all" and then splitting into array at ">" is:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <HTML>
> <head>
> <title></title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> </head>
> <BODY>
> TTY:helpc.htm
> </body>
> </html>

Almost every ">" is follwoed by a newline character.  I'm guessing that
what looks to you like "TTY" is, in fact "\nTTY" (and hence 4 characters
long).

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#28832

Fromjoe <mt@invalid.com>
Date2015-10-17 13:57 +0300
Message-ID<h5a42bdo06su2sf2ns5kpsq7b6vu4rgm3m@4ax.com>
In reply to#28829
Thanks! The front "\n" was the culprit! I spent hours and hours in the debugger!


Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

>joe <mt@invalid.com> writes:
>
>> In my javascript I use XMLHttpRequest to get an htm file into text memory
>> (varaibale "all") and them split the text into an array with following code:
>>
>> ...
>>             var apu2=all.split(">");
>>             var ii=apu2.length;
>>             for (i=0;i<ii;i++)
>>                {
>>                allte=apu2[i].substring(0,4);
>>                if (allte=="TTY")
>
>There's a big clue here.  How can a 4 character string ever equal "TTY"?

The code string I posted was edited from (0,3) and it was just left in my post as
I tested with (0,3) and (0,4) and I was thing there was an \n in the end - not
font.

>
><snip>
>> The local file I'me reading into "all" and then splitting into array at ">" is:
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>> "http://www.w3.org/TR/html4/loose.dtd">
>> <HTML>
>> <head>
>> <title></title>
>> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
>> </head>
>> <BODY>
>> TTY:helpc.htm
>> </body>
>> </html>
>
>Almost every ">" is follwoed by a newline character.  I'm guessing that
>what looks to you like "TTY" is, in fact "\nTTY" (and hence 4 characters
>long).

[toc] | [prev] | [next] | [standalone]


#28833

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-10-17 14:59 +0200
Message-ID<4114734.0R2ZEXP6cX@PointedEars.de>
In reply to#28829
Ben Bacarisse wrote:

> joe <mt@invalid.com> writes:
>>             var apu2=all.split(">");

Given your input, that is a very bad idea.  You should respond with either 
of plain text, JSON, or XML, and use appropriate parsers instead.

>>             var ii=apu2.length;
>>             for (i=0;i<ii;i++)
>>                {
>>                allte=apu2[i].substring(0,4);
>>                if (allte=="TTY")
> 
> There's a big clue here.  How can a 4 character string ever equal "TTY"?

When it is only three characters long: "TTY".substring(0, 4) == "TTY".

That was easy.
 
> <snip>
>> The local file I'me reading into "all" and then splitting into array at
>> ">" is:
>>
>> […]
>> <BODY>
>> TTY:helpc.htm
>> </body>
>> </html>
> 
> Almost every ">" is follwoed by a newline character.  I'm guessing that
> what looks to you like "TTY" is, in fact "\nTTY" (and hence 4 characters
> long).

If they split this input on “>”, then there is an array element 
"\nTTY:helpc.htm\n</body", where "\n" can be either this (Unices)
or one of "\r\n" (Windows) or "\r" (Mac OS < 10).

They should use a debugger next time; see the FAQ.
 
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#28834

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-17 14:37 +0100
Message-ID<877fmlpqdm.fsf@bsb.me.uk>
In reply to#28833
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Ben Bacarisse wrote:
>> joe <mt@invalid.com> writes:
<snip>
>>>             var ii=apu2.length;
>>>             for (i=0;i<ii;i++)
>>>                {
>>>                allte=apu2[i].substring(0,4);
>>>                if (allte=="TTY")
>> 
>> There's a big clue here.  How can a 4 character string ever equal "TTY"?
>
> When it is only three characters long: "TTY".substring(0, 4) == "TTY".

Thou wouldst make a good fool[1].

> That was easy.

What was?  It's certainly not an answer to my (rhetorical) question.

[1] FOOL    The reason why the seven stars are no more than seven is a pretty
            reason.
    LEAR    Because they are not eight?
    FOOL    Yes indeed. Thou wouldst make a good fool.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#28835

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-10-17 16:11 +0200
Message-ID<2705941.Mo4q7LazKx@PointedEars.de>
In reply to#28834
Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Ben Bacarisse wrote:
>>> joe <mt@invalid.com> writes:
>>>>                allte=apu2[i].substring(0,4);
>>>>                if (allte=="TTY")
>>> 
>>> There's a big clue here.  How can a 4 character string ever equal "TTY"?
>> When it is only three characters long: "TTY".substring(0, 4) == "TTY".
> […]
>> That was easy.
> 
> What was?  It's certainly not an answer to my (rhetorical) question.

It can be beneficial to read entire articles.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#28830

From"danca (Daniele Campagna)" <cyberdanny@tiscalinet.it>
Date2015-10-17 12:21 +0200
Message-ID<mvt765$nfj$1@dont-email.me>
In reply to#28827
Il 10/17/2015 12:00 PM, joe ha scritto:
> In my javascript I use XMLHttpRequest to get an htm file into text memory
> (varaibale "all") and them split the text into an array with following code:
>
> ...
>              var apu2=all.split(">");
>              var ii=apu2.length;
>              for (i=0;i<ii;i++)
>                 {
>                 allte=apu2[i].substring(0,4);
>                 if (allte=="TTY")
allte is 4 char long.



-- 
"Everybody should pay taxes with a smile"
I tried, but they want money.

[toc] | [prev] | [next] | [standalone]


#28831

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-10-17 12:28 +0200
Message-ID<XnsA5367EE9B1D4Feejj99@194.109.6.166>
In reply to#28827
joe <mt@invalid.com> wrote on 17 Oct 2015 in comp.lang.javascript:

>             var apu2=all.split(">");
> ...
> 
> I then have apu2 as:
> apu2[0]  "-><!DOCTYPE.."

No, by using split(">") all the ">"'s are consumed.

> What I am doing wrong?

Do a better job debugging,
using alert() and/or console.log
[if you are working clientside javascript]

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web