realbasic-nug
[Top] [All Lists]

Re: WritePString weirdness...

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: WritePString weirdness...
From: Joe Strout <joe at inspiringapps dot com>
Date: Fri, 28 Mar 2008 20:07:05 -0600
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <226027DE-9E67-4701-90AD-12E8F3383CF6 at rbclass dot com> <A652AB13-FCF7-4D95-B6B1-5EC6EC3E84DE at inspiringapps dot com> <3E14F3DA-1A0F-47A7-A23A-5561C8EFDFC3 at rbclass dot com>
On Mar 28, 2008, at 7:10 PM, Mark O'Neill wrote:

> Ah, right. Didn't know that. I just opened the BinaryStream example
> that was shipped with RB - having never worked with files in RB before
> - and that's what they used in the example.

That example probably dates back to OS9 days.  It should be updated  
or removed.

> What should I use instead for storing text? I don't see a ReadString
> or WriteString in the help file or the contextual helper - or should I
> just avoid BinaryStreams for preference files and just use a text  
> file?

You can read and write strings in binary files just fine, but as with  
any binary file, you have to define (i.e. make up) the format.   
Perhaps you'll choose to write out the length in bytes as a long  
integer, followed by the data in UTF-8 format.  Upon reading, do the  
reverse (and remember to define the encoding as UTF-8).  This is  
similar to PString, but removes the 255-byte limit and uses a more  
sensible encoding.

Or, just use a text stream; that's certainly much easier if all your  
data is text.

Cheers,
- Joe

--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com



_______________________________________________
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>