So I have a string like this:
local str = "Hello Friends "
how do i remove that space after friends? as its not needed
So I have a string like this:
local str = "Hello Friends "
how do i remove that space after friends? as its not needed
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.
" " isn't a special character and thus you don't need to have the % sign.
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.
5 comments
Couldn't you just set the string from "Hello Friends " to "Hello Friends"?
well im making a kick command and you can do kick player reason. so no
Why do you have a space after the string? http://xyproblem.info
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?
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.