newTextBox & international alphabets

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")

image

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:

  1. it has to be added in “build.settings” file
  2. it has to be added in lua-file:
    local utf8 = require( “plugin.utf8” )
  3. 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”

1 Like

If you have “\n\n” in your string and you use gsub like you’ve specified, then it should do what you want.

Have you checked the regex if it is indeed two sets of newlines “\n” and not carriage return followed by a newline, i.e. “\r\n” ?

1 Like

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”)

I used them together… like this:

our_text = string.gsub(our_text, "\r\n", "\n")
our_text = string.gsub(our_text, "\n\n", "\n")

works fine…
If I put line#2 above line#1, then it does not work :slight_smile:
I cannot figure out why it works in such a way… but it works the way I want :smiley:
Thanks again!