Simple question about :split()

Hello! so I was wondering
I am doing for an admin commands like this:

:message all hello it’s me xddd
For example, but, how can I do for it detects from >= 2 than splits?
Example

local message = " 1 2 3 4 5 6 7"
local tosplit = message:split(" ")
print(tosplit >= 3)

Obviosuly, this will give error, as i’m trying to compare number with table, but, how can I make like that?
like for example, that it says all message from 3 to upper
like, I want it to print like:
" 4 5 6 7"

Since split returns a table just do #tosplit >= 3.

I tried that but doesn’t works, like, it prints true for some reason lol

As documented on string, the :split method returns a table.

So to get the number of elements in a table, use the # infront.

print(#tosplit >= 3)

It is supposed to. Since a >= b evaluates to true if a is greater than b. What did you expect for it to do?

It returns true
|| 30 chars ||

What’s your end-goal here? What are you trying to accomplish? Knowing your end-goal will help us solve your problem a bit better. Because there’s multiple ways to go about printing only a portion of a table.

1 Like

Basically, so let’s suppose I have a message as I showed

local Message = "/message all hello how's your day"
local SplittedMessage = Message:split(" ")

-- What I want to do it's to remove the first 2 spaces and send message to all the other message ignoring the first 2 spaces
local SendMessage = SplittedMessage = [3]..[4]..[5]..[6] -- Exchange of making this, I would want to make like >= [3] But doesn't works with split

Perhaps then look into table.concat

That can take a table, and join the elements together.

Well, I already knew about table.concat I was just wondering if there was a way of doing like how I did but I guess not really easy :confused: Thank you! :slight_smile:

Have you studied the arguments to table.concat? In particular the third argument named i?

1 Like

table.concat is waaaay easier. It is the opposite of string.split in fact, i.e. they undo each other much like multiplication and division.

local s = table.concat(tosplit, " ", 3, 6)

This concatenates the third, fourth, fifth and sixth element of the table with spaces in between.

1 Like

If you want to keep it as a table, you could use table.unpack and put it into a new table:

tosplit = {table.unpack(tosplit, 5)}

Where 5 is the starting index.

3 Likes