I have found that international alphabet symbols in native.newTextBox go as two symbols. Just like in old sytle SMS that had (to my memory) 80 symbol limt (160 as per Google) if you use Egnlish… and twice less if you use Greek, Cyrillics, etc.
When I work with TB, I want to limit number of symbols… I just cut it by 300. If by any chance I use BOTH English & Russian, a strange sybmol appears at the end: � I is “a half” of a any Russian letter that is at the end of the string. I cannot get rid of it by string.gsub!
Also, does anybody know how to get rid of two new-line sybmols? ("\n\n")
local function Req_textListener_sub( event )
if event.phase == "editing" then
local our_TB = event.target
local our_text = our_TB.text
our_text = string.gsub(our_text, "�", "") -- DOES NOT WORK!
our_text = string.gsub(our_text, "\n\n", "\n") -- DOES NOT WORK!
our_text = string.gsub(our_text, "11", "1") -- Works fine! (added just to check that gsub works)
local a_length_int = string.len(our_text)
if a_length_int > 300 then
our_text = string.sub(our_text, 1, 300)
-- � can appear here if international alphabets used together with English...
our_text = string.gsub(our_text, "�", "") -- DOES NOT WORK again :-(
end
our_TB.text = our_text
end
end
I just found a solution! Since there are no answers, and some might encounter the problem too, I will explain what I did. First of all the problem is that I use utf8 in the TB, it means the string needs special handling. Hopefully there is the uff-8 plugin:
it has to be added in “build.settings” file
it has to be added in lua-file: local utf8 = require( “plugin.utf8” )
now let’s use utf8.width(our_text) instead of string.len(our_text), utf8.gsub instead of string.gsub
and utf8.sub instead of string.sub
Problem solved… But I am still looking for a solution to replace “\n\n” to “\n”
Thank you for the hint… it makes sence!
So, one line like this did not work for me: our_text = string.gsub(our_text, “\r\n”, “\n”)
Original line like this did not work for me either, that’s why I asked… our_text = string.gsub(our_text, “\n\n”, “\n”)
works fine…
If I put line#2 above line#1, then it does not work
I cannot figure out why it works in such a way… but it works the way I want
Thanks again!