realbasic-nug
[Top] [All Lists]

Re: WritePString weirdness...

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: WritePString weirdness...
From: Harrie Westphal <harriew at frontiernet dot net>
Date: Sat, 29 Mar 2008 10:48:43 -0500
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> <A0720DC7-6E68-4825-B1E7-06FA772B07E7 at inspiringapps dot com> <A08DAFF0-4131-4C31-BE88-965126CC576F at rbclass dot com> <09004169-C758-401C-BF6E-6FB615336097 at rbclass dot com>
On Mar 29, 2008, at 12:01 AM, Mark O'Neill wrote:
> Well, I'm not sure why that "not" character kept appearing before the
> © symbol, (could it be an RB bug in 2007r4?) but as I needed a "Text
> To HTML Code" function for another part of my program, I've used that
> routine to convert the string to html-safe code. So from the above
> example, the string on file now looks like:

Boy, I sure can't duplicate that on my machine,a Mac using RB2008R1.  
I wrote a little program with a window with three statictext fields  
and three pushbuttons labeled Binary, PString and Text. Each  
pushbutton creates a different file placing your string,  
"CopyrightText=©", into it and then reads it back out. I cannot see a  
not symbol(¬) when viewing any of the 3 files in BBEdit nor does it  
appear in the corresponding statictext field in the window after the  
corresponding pushbutton is clicked.

Here is the code for the three pushbutton action events

pbBinary pushbutton
===================
   Dim f As FolderItem
   Dim bs As BinaryStream
   Dim sInput, sOutput As String
   Dim lng As UInt32

   f = GetFolderItem("BinaryFile")
   if f = nil then
     beep
     MsgBox "Unable to get FolderItem to BinaryFile"
     return
   end if
   if f.exists then
     bs = f.OpenAsBinaryFile(True)
   else
     bs = f.CreateBinaryFile("whatever")
   end if
   sOutput = "CopyrightText=©"
   lng = lenb(sOutput)
   bs.WriteUInt32 lng  // write out string length
   bs.Write sOutput  // write out the string
   bs.Position = 0  // reposition to start of file
   lng = bs.ReadUInt32  // read in string length
   sInput = bs.Read(lng, encodings.UTF8)  // read in the string
   bs.Close
   stBinary.Text = sInput  // display string read in

ppbPString pushbutton
=====================
   Dim f As FolderItem
   Dim bs As BinaryStream
   Dim sInput, sOutput As String
   Dim lng As UInt32

   f = GetFolderItem("PStringFile")
   if f = nil then
     beep
     MsgBox "Unable to get FolderItem to PStringFile"
     return
   end if
   if f.exists then
     bs = f.OpenAsBinaryFile(True)
   else
     bs = f.CreateBinaryFile("whatever")
   end if
   sOutput = "CopyrightText=©"
   bs.WritePString sOutput  // write out string  as a PString
   bs.Position = 0  // reposition to start of file
   sInput = bs.ReadPString(encodings.UTF8)  // read in the string
   bs.Close
   stPString.Text = sInput  // display string read in

pbText pushbutton
=================
   Dim f As FolderItem
   Dim tOut As TextOutputStream
   Dim tIn As TextInputStream
   Dim s As String

   f = GetFolderItem("TextFile")
   if f = nil then
     beep
     MsgBox "Unable to get FolderItem to TextFile"
     return
   end if
   tOut = f.CreateTextFile
   tOut.WriteLine("CopyrightText=©")  // write out the string
   tOut.Close
   tIn = f.OpenAsTextFile
   tIn.Encoding = Encodings.UTF8
   s = tIn.ReadAll  // read in the string
   tIn.Close
   stText.Text = s  // display the string

=== A Mac addict in Tennessee ===

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