Unicode from Variable?
Devin Asay
devin_asay at byu.edu
Tue Nov 25 10:31:17 EST 2008
On Nov 24, 2008, at 5:56 PM, Scott Rossi wrote:
> Recently, Devin Asay wrote:
>
>>> Anyone know if it's possible to set the unicodeText of a field to
>>> data
>>> contained in a variable? So far all the examples I've found involve
>>> setting
>>> the unicodeText from an external binary file, or setting the
>>> unicodeText of
>>> one field to the unicodeText of another.
>>
>> Yes, you can do this. All you have to do is make sure that the
>> variable contains valid unicode text, then do:
>>
>> set the unicodeText of fld "babel" to varFullOfUnicode
>>
>> It works with custom properties, too.
>>
>> set the unicodeText of fld "babel" to the uniStoredText of me
>>
>> As Mark said, if it's not already uni-encoded you have to run it
>> through uniencode() first.
>
> I guess I'm not understanding when text should or should not be
> "encoded".
>
> I have an external text file which was saved as UTF-16 that is read
> into a
> variable. I am trying to find lineOffsets of various strings in the
> variable text, but so far I keep getting values of 0 (not found). I
> have
> tried using "set the useUnicode to true" before reading the variable
> (and
> without) and still get 0.
>
> If I first place the text in a field (set the unicodeText of fld xyz
> to url
> ("binfile:" & tFile)), I am able to find the offsets.
I'm not sure what all the implications are of using offset functions
with unicode text. That's one area I've not experimented with much.
>
>
> So do I need to do anything to the variable text first? Encode?
> Decode?
> Something else?
This is how I would do it:
put url "binfile:myUnicodeFile.utx" into myUniVar
set the unicodeText of fld "myUniFld" to myUniVar
This is all assuming that you're sure the unicode file is UTF16
encoded and was produced by a processor that uses the same byte-order
as yours. (PPC and Intel are different, for example.)
If the text file is UTF-8, do it this way:
put url "binfile:myUnicode8file.ut8" into myUniVar
set the unicodeText of fld "myUniFld" to uniencode(myUniVar,"UTF8")
HTH
Devin
Devin Asay
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode
mailing list