On Mar 29, 2008, at 1:01 AM, Mark O'Neill wrote:
> Hi All,
>
> On 29 Mar 2008, at 03:04, Mark O'Neill wrote:
>
>> I checked my code, and I even hard-coded the following:
>>
>> if f<> nil then
>> txtOut=f.CreateTextFile
>> txtOut.WriteLine("CopyrightText=©") // notice this line
>> txtOut.Close
>> end if
>>
>> but this is the result I get in the file...
>>
>> CopyrightText=©
>>
>> Am I missing something here?
>>
>> If anything, this points to the fact that it wasn't the
>> WritePString's
>> fault - and as I've hard-coded that text and writing to a text
>> stream,
>> what am I doing wrong?
>
> 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:
>
> CopyrightText=©
>
> Seems an unnecessary step if you ask me, but works now all the same.
> Obviously, I decode it when it's read back in! :)
I"m sure Joe is correct when he suggests you're hitting a text
encoding issue. I understand and even acknowledge the necessity of
text encoding, but despise is not too strong a word for how I feel
towards the implementation we're using.
What I think you're seeing is that the copyright symbol is translated
to 2 characters in UTF8 which is the default for strings in RB. You
can verify by msgbox str( len( CopyrightText)) + " " +
str( lenb( CopyrightText))
and I think you'll find the binary length is one bigger than the text
length. Because RB knows that the string is UTF8 encoded it displays
properly. However, once you read it in from ReadPString it doesn't
know that anymore as the encodings aren't saved along with the binary
data.
So, regardless of how you write the string, you may have to redefine
the encoding when you read it back in. try something like:
dim s as string
s = TheBinaryStream.ReadPString
CopyrghtText = s.defineencoding( encodings.UTF8)
or something, thats from memory, but I think thats how it works. I
THINK you'll find that the problem is then solved.
To solve it across the board I believe that you can set the encoding
that is the default for the binary stream? And even if you do that I"m
not sure that readPString will honor that because as Joe says it's an
old call that was never text encoding savvy. So you may have to create
your own read routines that do this for you each time.
Thanks,
James
James Sentman http://sentman.com
http://MacHomeAutomation.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|