Printing a string, and omit the first word

This is my first forum post, so bear with me here

Lets say I have a string with a value of I eat fruit, but I don’t want to print the first word (I). So I expect eat fruit as an output.

How would I come across this?

Appreciate the help

You can’t delete the first character of a string

local oldstring = "I want fruit"
local newString = string.sub(oldString,2)

But you can use string.sub and get the 2nd character

Well, I see here that others can print the first word in a string, so assuming… you can print everything except the first word.

Or is it somehow really not possible?

1 Like

I’ll give some background info here,
I am working on a very simple chat command system… where after someone types the command, it will send the text after the command to the server to its thing.
What they could say:
/me Eats all the apples

What I care about:
Eats all the apples

And the part I care about will never be the same. Same for the command.

Would this work?

oldstring = "I want fruit"
local newString = string.sub(oldString, 2, math.huge())
local commandLength = 3
local messageLength = string.len(message)
local FormatString = string.sub(message, commandLength, messageLength )
1 Like

You should write correct message Length

I can just do

local command = prefix..suffix
local commandLen = string.len(command)

And in my case, will be 3

if anyone else is looking at this post and wants a more one size fits all solution, you can just do this:

local Command = "/randomcommand this is a test"
local Formatted = string.gsub(Command, "%b/ ", "", 1)

This will work on any command regardless of the length of it, as long as it starts with a slash and is seperated by a space.

3 Likes