realbasic-nug
[Top] [All Lists]

Re: Working with bytes vs characters

To: "REALbasic NUG" <realbasic-nug@lists.realsoftware.com>
Subject: Re: Working with bytes vs characters
From: "Paul Rehill" <paul.rehill@gmail.com>
Date: Sun, 28 Sep 2008 17:18:01 +1000
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com; dkim=neutral (body hash did not verify) header.i=@gmail.com
Delivered-to: listarchive@realsoftware.com
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=ZS3NSZhfg0cixWiMEfnsDKlLUD9KPZ9HHukHPso3La8=; b=ZbirlPhu62GaqnqpZyDrMLIIDcUgkjqOshItDSnlWDZAkf2M8aGcim7B+1eIWsHBSz xnXnl0mTrhuDu7WR+YYYVOzcRaF8zeUrj0O7ch+L2HEAtI7PjiFJSsYPQ2Xv4ZgR7O3O gmRIH4Kgno3EEXN2TqeMsSqSlhcX0DzcXJKpU=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=a8OBMIBYqMh+dtSOniBWd+AwyLzqu4mZc7DSpbGcOdFmK0pLAtquuog6TOqXnijaYc YRgUDW/5UNwewUrn9YNPghmBbV15y4whtUwxWv5HRmLjJ3ha3OlVO0Jd7yMVp1EyjCx4 Ahe0dGkZsTl8RqAuCmGpNFhkUeoxFu7iojoBQ=
In-reply-to: <f72ec0cb0809272225y327ef795o4493501ce3cf09fa@mail.gmail.com>
References: <f72ec0cb0809272225y327ef795o4493501ce3cf09fa@mail.gmail.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
On Sun, Sep 28, 2008 at 3:25 PM, Paul Rehill <paul.rehill@gmail.com> wrote:
> I am trying to code to calculate the number of bytes rather than
> characters to read incoming data from sockets.
>
> I am aiming to read in data to the end of some closing tag, let's call
> it Str1="</sometag>" that has been extracted using the Lookahead
> function for a socket.  sLook is the full string data obtained using
> the LookAhead function.
>
> If I was only working with characters and not bytes, I could use the
> following code to determine iTagEnd which represents the number of
> characters to be read by a socket's read function:
>    iFoundTag=Instr(sLook, Str1)
>    iTagLength=Len(Str1)
>    iTagEnd=iFoundTag+iTagLength-1
>
> But since I am working with bytes, I have replaced Instr with InstrB,
> Len with LenB and 1 in the above code with LenB(Left(Str1,1)) as in
> the following code:
>
>    iFoundTag=InstrB(sLook, Str1)
>    iTagLength=LenB(Str1)
>    iTagEnd=iFoundTag+iTagLength-LenB(Left(Str1,1))

Looking at this again.  I think I should still be using
iTagEnd=iFoundTag+iTagLength-1 even when dealing with bytes as
iFoundTag returns the first byte as an integer (rather than 2 bytes
when each character may be represented by 2 bytes) and so I need to
subtract 1 to capture the correct number of bytes to be read up to and
including the end tag.

Is this right?

Thanks

Paul

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>