Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I remove a space after a string?

Asked by 4 years ago
Edited 4 years ago

So I have a string like this:

local str = "Hello Friends "

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

0
Couldn't you just set the string from "Hello Friends " to "Hello Friends"? blarp_blurp645 63 — 4y
0
well im making a kick command and you can do kick player reason. so no Itzlewis99 26 — 4y
0
Why do you have a space after the string? http://xyproblem.info hiimgoodpack 2009 — 4y
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? ChristianTRPOC 64 — 4y
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. 123nabilben123 499 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

1
" " isn't a special character and thus you don't need to have the % sign. hiimgoodpack 2009 — 4y
0
You're right, I'll edit the answer. Thank you for catching that. SteelMettle1 394 — 4y
Ad

Answer this question