How do i "backspace" a string?

im working on a thing and i need a backspace button.
For example
“I farted”
backspace
“I farte”
backspace
“I fart”

How do i delete the last letter of a string?

Thanks!

Use simple Sign for example like emotes (/, :, ; )

i dont understand what do you mean

You can use string.sub() like this:

string.sub(stringName, 1, -2)

string.sub gets a slice of a string with negative indices starting from the end of the string.

1 Like

No way… Sorry I misunderstood,

-- (there is no difference; i just wanted to include it)
local MyString = "Hello world!"
MyString = MyString:sub(1, -2)

print(MyString) --> 'Hello world'
2 Likes

Neither of these work
Heres how i did it:

if KeyCode == "BackSpace" then
			CMessage:sub(1, -2)
			chat.Text = CMessage
		end

(Keycode is “BackSpace” and CMessage is just a tring)
(Chat is a textbox)

1 Like

a keycode would be Enum.KeyCode.Backspace

our sub example would work just fine

no, Keycode is “BackSpace” (a tring) its not an Enum

nevermind i see the problem

stringName = string.sub(stringName, 1, -2) -- Set stringName equal to the new string
CMessage = CMessage:sub(1, -2)
4 Likes

that works, Thanks!
char limit

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.