Hi I would like to know how to remove words from a value.
Like this
local t=30…“hi”
t-text=t.text=-“hi”
I know that wouldn’t work but it’s just to demonstrate what I want to which is removing words, from a value that includes both words and numbers
Hi I would like to know how to remove words from a value.
Like this
local t=30…“hi”
t-text=t.text=-“hi”
I know that wouldn’t work but it’s just to demonstrate what I want to which is removing words, from a value that includes both words and numbers
I think the specific function you seek is string.gsub()
-- Some examples -- 1 local text = "lua "..15.." cool" print( 1, text) -- 2 text = string.gsub( text, "lua", "Corona" ) print( 2, text) -- 3 text = string.gsub( text, "Corona 15", "" ) text = string.gsub( text, " ", "" ) print( 3, text )
Okay thanks i will try and figure out how it works!
Ok i figured out something now
print( string.gsub( “i like programming in lua”, “(lua)”, string.len ) )
but when i run it random numbers apper
this is what it printed
i like programming in 3 1 why does 3,1 appear it makes no sense to me
The pattern is
string.gsub( s, pattern, repl [, n] )
so therefore the usage is
print( string.gsub( "i like programming in lua", "lua", "c#" ) )
Okay but now it just says
i like programming in #c 1
why is there a 1 at the end?
in the console that whats i’m worried about, beacuse if i want to display text i don’t want an extra 1 in my value
Okay it’s finally solved so the extra numbers that was coming at the end of my code was because of the amount of left parentheses.
I now removed the parentes from print by doing this.
local val=“corona”…12
local t = string.gsub( val, “%a”, “” )
print(t)
No the extra number is the amount of changes made. The documentation should actually say
local replacedString, NumberOfOccurrencesRepalced = string.gsub( s, pattern, repl [, n] )
I think the specific function you seek is string.gsub()
-- Some examples -- 1 local text = "lua "..15.." cool" print( 1, text) -- 2 text = string.gsub( text, "lua", "Corona" ) print( 2, text) -- 3 text = string.gsub( text, "Corona 15", "" ) text = string.gsub( text, " ", "" ) print( 3, text )
Okay thanks i will try and figure out how it works!
Ok i figured out something now
print( string.gsub( “i like programming in lua”, “(lua)”, string.len ) )
but when i run it random numbers apper
this is what it printed
i like programming in 3 1 why does 3,1 appear it makes no sense to me
The pattern is
string.gsub( s, pattern, repl [, n] )
so therefore the usage is
print( string.gsub( "i like programming in lua", "lua", "c#" ) )
Okay but now it just says
i like programming in #c 1
why is there a 1 at the end?
in the console that whats i’m worried about, beacuse if i want to display text i don’t want an extra 1 in my value
Okay it’s finally solved so the extra numbers that was coming at the end of my code was because of the amount of left parentheses.
I now removed the parentes from print by doing this.
local val=“corona”…12
local t = string.gsub( val, “%a”, “” )
print(t)
No the extra number is the amount of changes made. The documentation should actually say
local replacedString, NumberOfOccurrencesRepalced = string.gsub( s, pattern, repl [, n] )