Hello, how i can remove special character from the text, I looked in other posts for ways, but they didn’t help me.
This symbol appears when I write in a language other than English
EXAMPLE::
i want remove this - �
from text - Hello!�
how i can do this?
code:
for i = 1,#text do
if not voice then
script:FindFirstChild("DefaultVoice"):Play()
end
textLabel.Text = string.sub(text,1,i)
-- example: Hello buddy�
-- object -> � to remove
wait()
end
not sure how to fix but i know this happens because some special characters take up more than 1 byte of space, so when you use :sub() it gets 1 byte instead of 1 character which gives you an unknown character
textLabel.Text = string.sub(text,1,i)
if i == #text then
textLabel.Text = string.sub(text,1,#text) -- changed this because lua index starts at 1 so the end is #text
end
Writing a text Separately, for example: H e l l o t h e r e !
and create UIListLayout and adding one letter at a time.
code:
function dialogueHandler.write(Holder,text,voice)
local function SplitMyString(str)
local results = {}
local current = ""
for i=1,#str do
local letter = string.sub(str,i,i)
if letter == " " then
table.insert(results, current)
current = ""
else
current = current..letter
end
end
if #current > 0 then
table.insert(results, current)
end
return results
end
local function createTXT(letter)
local v = script:FindFirstChild("text_example"):Clone()
v.Text = letter
v.Parent = Holder
end
local results = SplitMyString(text)
local currWords = 0
for i,v in pairs(results) do
currWords += 1
end
local stringValue = Instance.new("StringValue")
for i = 1,currWords do
if not voice then
script:FindFirstChild("DefaultVoice"):Play()
end
createTXT(results[i])
wait()
end
end
I don’t feel like that’s the best method to resolve your issue, and why exactly are you making a new textlabel for each character? what are you attempting to achieve with that?
edit
If you are needing to only have a-z, 0-9 and spaces I’d recommend doing this instead
local str = "Hello bu�dd�y 123!@#"
local clean_str = string.gsub(str, '[^a-zA-Z0-9 !?,.]', '')
print(clean_str) -- You'll get output of: Hello buddy 123!
Going off your making a dialogue system It’s best to assume your probably wanting to have the text appear as the voice speaks but you don’t need a textlabel each time. Roblox added a property to textlabels & other text items “MaxVisibleGraphemes” by default its “-1” meaning the entire text would be visible, if you have it 0 then no letters show, 1 = 1 letter 2 = 2 letters, etc
You can tween this property as well, I’d review the documentation here
The “question in a diamond” is an indicator that you’re working with UTF8 data. UTF8 is a different way of encoding text into memory by splitting up codepoints across multiple characters.
Lua’s built-in sub function is built to work on a byte level which can result in these chars being chewed up and malformed, resulting in the diamond.
Your best bet to handle UTF8 is to look into the built-in utf8 library.
The thing is, I wasn’t interested in string methods. And the only thing I did was to do as I described above.
After this situation, I looked into it. And I realized that I still can’t solve this problem, string only works with English letters and characters like comma or period, or I’m not too experienced in it.
I tried your code, but it didn’t work for me.
Because - your code is designed for English letters, but my letters are Russian. I wrote above that “This symbol appears when I write in a language other than English”.
I think your code is good for English version if you need to clear this symbol. But unfortunately it doesn’t work for me.
(I’ll still give you a solution).
If there is a desire to solve as your own method, then try to write this text: “Привет Мир” (in Russian) without the � symbol appearing.
If you succeed, I will use your code in my game.
And I’ll be very grateful to you
maybe you’ll be one of the first to solve the problem.
I couldn’t find any other choice but to use the system I wrote above
(with this system I can animate the appearing letters, and make more beautiful).
If interested: �
I have seen this problem in many games, and even very popular ones. If you translate the game via ESC to another language, these characters can appear when writing text.
I have always been annoyed by this, as the game is easier for me to perceive in my native language. So I decided to add my own custom translation into Russian and English in my own game.
Nevertheless, thanks for your and everyone else’s help.
btw, the game deepwoken uses the same approach as I did in my script written above. So they don’t have this problem and they also animate the appearance of letters with this method