realbasic-nug
[Top] [All Lists]

Re: 2 quick encoding questions

To: "REALbasic Network Users Group" <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: 2 quick encoding questions
From: maclists at additional dot com
Date: Sun, 29 Feb 2004 22:13:50 -0500
References: <a06020412bc681dc734b2 at [192 dot 168 dot 1 dot 101]> <a05300b09bc683bbe1e1b at [10 dot 10 dot 13 dot 3]>
At 6:11 PM -0500 2/29/04, maclists at additional dot com wrote:

1) Is the text in a text-edit field with System font /always/ UTF8 encoded

No.

 (or, for example, can the user's selected locale or host OS change that)?

It might.

Dragging a string from elsewhere seems to change the encoding to UTF16.

Since I'm saving the text (as part of a larger set of binary data), I'll save the encoding code with the text, and use that when I read it back:

     // Save the encoding, then the string
   myBinaryStream.writeLong theEditField.text.Encoding.code  // save the code?
   myBinaryStream.write theEditField.text
    ...
     // Read the encoding then the string
   theSavedEncoding = myBinaryStream.readLong
theEditField.text = myBinaryStream.read (theStringLength, Encodings.GetFromCode(theSavedEncoding))


2) How can I get the underlying bytes in a UTF8 string (for example, to transmit them)?

You already have them. If, for example, by "transmit" you mean via a socket, then MySocket.Write theString transmits the bytes.

I can get the byte count using LenB, but then I'm stuck. Do I use Asc or AscB on each character and expect an integer value that will take 1, 2, 3, or 4 bytes to represent, or is there a better way?

I don't understand the question. Why do you want the numeric values of the bytes or characters? Why not just transmit the string?

I want to try some compression & coding things on the stream. However, I realized that to access the byte-sequence, I can probably save the encoding, then force it to be nil, and then I'll see the text as binary data.

Cheers,

Dave

"If the code and the comments disagree, then both are probably wrong."
 - Norm Schryer

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

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

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