Page 1 of 1

Split Unicode-Mixed field into array

Posted: Wed Oct 17, 2012 1:24 pm
by strongbow
Has anyone split old "mixed" fields (i.e. fields containing a mix of 1-byte e.g. English and 2 byte e.g. Japanese chars) into arrays successfully since the fields were changed significantly in Release 5.5?

I have a current project running fine in 4.6.4 and now it breaks under 5.5 with the new unicode (it just works!) field changes. Now I'm not even sure now how to successfully display the text that is in Japanese in the field at all (apart from using the htmlText of the fld).

I have the following text in a field:

en English
jp 日本語
de Deutsch

Previously I could easily split this array and use the japanese text in another btn or field. But now it's really not clear to me how I should go about this. I have read the release notes about unicodeLabel, unicodeText etc etc but still it's not very clear. Or perhaps I'm trying to do too much in the same way as I previously did, rather than changing my approach.

What I'm trying to do is to take the contents of a field (contents above) and then grab item 2 of line 2 (i.e. the word "Japanese" in japanese) and display that in a field or button label.

Attempting using something like the following code:

Code: Select all

put the unicodeText of fld "LangCodes" into tTemp
set the itemDelimiter to tab
put unicode item 2 of line 2 of tTemp into fld "test"
Has anyone sorted this out well since 5.5 came out?

Also, Is it possible to use the split command on a field containing Unicode text (ie. to store it in an array)? Or do we have to do it all manually?

Thanks for help, once again, on Unicode stuff...

cheers!

Re: Split Unicode-Mixed field into array

Posted: Wed Oct 17, 2012 5:43 pm
by strongbow
I can put the text directly from 1 field to another, but I want to be able to set the UnicodeText of a field from an array or variable.

i.e. the following works:

Code: Select all

set the unicodetext of line 1 of field "test" to the unicodetext of item 2 of line 2 of fld "Langcodes"
but not from a variable as far as I have been able to test so far.

i.e. this does not work:

Code: Select all

put unicode item 2 of line 2 of tTemp into fld "test"
Ideas anyone?

Re: Split Unicode-Mixed field into array

Posted: Wed Oct 17, 2012 9:26 pm
by snm
Try uniEncode and uniDecode

Marek

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 8:49 am
by strongbow
Yup, have tried a bunch of variations using unidecode and uniencode, nothing works for me so far.

To summarise what my problem is:

I would like to store the UnicodeText of a field into a variable (or array) and then somewhere else set the unicodeText of a field to a chunk of that variable.

Is it possible?

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 11:52 am
by snm
Make 2 fields on card named: Field1 and Field2
Make 2 buttons: Save and Restore
Put scripts into buttons
Save:

Code: Select all

on mouseUp
   set the cText of this card to uniDecode( unicodeText of field "Field1", "UTF8")
end mouseUp
Restore:

Code: Select all

on mouseUp
   set the unicodeText of field "Field2" to uniEncode (the cText of this card, "UTF8")
end mouseUp
Type something into Field1, click button Save, then click button Restore and in field Field2 should be the same text as in Field1.
Should work even if cText property of the card can be not the same as text in fields (it's utf-8 coded)

Hope it helped,
Marek

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 12:03 pm
by Klaus
So much for "Unicode! It just works!" :(

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 12:49 pm
by strongbow
Hi Marek

Yes, I can confirm that works. And storing it into a variable works similarly:

Code: Select all

put unidecode(the unicodeText of fld "LangCodes","utf8") into tTemp
set the unicodeText of fld "test" to uniencode(item 2 of line 2 of tTemp,"utf8") 
So, as Klaus says... "it, just, works"...

Not exactly marvellous I must say, but relieved to get that cleared up. So we need to use unidecode in order to get the unicode representation of the field into standard single-byte characters, and then uniencode in order to get it to convert to unicode again. And that's because all of our characters internally are single-byte presumably?

I see in Devin's Unicode summary (at: http://revolution.byu.edu/unicode/unicodeinrev.html ) that he mentions one part of this:
How to convert between Unicode (UTF-16) and UTF-8 text.
LiveCode displays non-Roman-alphabet languages using Unicode (UTF-16). You use the uniDecode and uniEncode functions to convert between UTF-16 and UTF-8.

The following statement converts a variable’s contents from UTF-8 to UTF-16, and places the resulting Unicode text in a field:

put uniEncode(myVariable,"UTF8") into field "My Field"
It just needs the extra bit about storing unicodeText from a field to a variable. e.g.

Code: Select all

put unidecode(the unicodeText of fld "My Field","UTF8") into myVariable
Hope someone else finds this useful!

Thanks again Marek!

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 1:04 pm
by snm
You are welcome :D
Marek

Re: Split Unicode-Mixed field into array

Posted: Thu Oct 18, 2012 1:24 pm
by Klaus
OK, to be honest, this release is not the one with the promised "Unicode! It just works" 8)

Anyway, its too bad RunRev is currently focussing so much on MOBILE (OK, big money here probably)
and neglects the desktop quite a bit...

Re: Split Unicode-Mixed field into array

Posted: Sun Apr 21, 2013 8:59 am
by snm
Agree with Klaus. Unicode should have the highest priority, as it's used on any platform. Now there are workarounds to use UTF8 but not always possible. We hope it'll be made in near future, as from this depends a lot.

Marek