Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I remove a space after a string?

So I have a string like this:

local str = "Hello Friends "

how do i remove that space after friends? as its not needed

5 comments

0

Couldn't you just set the string from "Hello Friends " to "Hello Friends"?

0

well im making a kick command and you can do kick player reason. so no

0

Why do you have a space after the string? http://xyproblem.info

0

Relating to @blarp_blurp64's comment, even if it's just a kick command then why can't you just write the player's name without having the space?

0

hey you should do what I did for my admin commands: I let the kick command decide if it wants the player's chat message or not which is spliced into spaces. It then grabs the first word and see if theres a player exists with that name then kicks them. I like it since it has full customizability and it's simple.

1 answer

✓ Accepted answer

I'm not exactly sure why you need this, but here is the code for removing a space from after friends:

local s = "Hello Friends "
local x = (s):gsub(" $", "")
print(x.."No space")

--Prints:
--Hello FriendsNo space

The parenthesis after gsub includes string manipulation characters (they're called wildcards). Basically you're searching the string with the parameters you provide and replace it with what's inside the last quotes. In this case I first add a space in the first quotes. The $ is an anchor point for the end of the string.

2 comments

1

" " isn't a special character and thus you don't need to have the % sign.

0

You're right, I'll edit the answer. Thank you for catching that.

This discussion is preserved as it was. New answers, comments, and votes are closed.