Harry
Harry

Reputation: 23

Remove the first word of a string in lua

What I'm looking for is something like the following, but it only applies to the first find it gets.

str:gsub("1", "")

I'd like it to only delete the first 1 it finds OR just the first word of the string.

How would I go about doing this?

Upvotes: 2

Views: 1639

Answers (1)

Mike V.
Mike V.

Reputation: 2205

try this:

local str = "234243 232564 se42"
local str, i = str:gsub("1", "",1)  
print (str,i)
str  = (i>0) and str or str:gsub("^.-%s", "",1) 
print (str)

only when there are spaces in the string (more than one word).

Upvotes: 3

Related Questions