Only getting one variable from two return values

print(string.gsub(string.gsub("oh_yeah", "_", " "), "-", ""))

this prints

oh yeah 0

because string.gsub returns two values, but I want only one value front. how can I only get first value of string.gsub?

Simply saving string.gsub to a variable seems to get rid of the number

local e = string.gsub(string.gsub("oh_yeah", "_", " "), "-", "")

print(e)

image

1 Like

…or add parenthesis around it.

print((string.gsub(string.gsub("oh_yeah", "_", " "), "-", "")))

For anyone stumbling upon this post like me, who wants the second value or larger, this command can be used: select()

Example:

local text = “Hello! Hello? Hello!?”
local helloCount = select(2, text:gsub(“Hello”, “”)) – Would normally print: ! ? !? 3
print(helloCount) – 3

1 Like