like suppose I have a string:
string = "abcdef"
how could I check a specific number of end characters so that I can do something like:
IF the end of string is "ef" THEN
....
END
thanks
How to check the end of a string?
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: How to check the end of a string?
Code: Select all
str = 'abcdef' --avoid using the global "string" as it's already used and you need it
if str:sub(-2) == 'ef' then --Thanks Kadoba (and Robin)
--etc.
end
Last edited by Nixola on Fri Jun 29, 2012 8:19 am, edited 2 times in total.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: How to check the end of a string?
I think you mean str:sub(-2).Nixola wrote:Code: Select all
str = 'abcdef' --avoid using the global "string" as it's already used and you need it if str:gsub(-1, -3) == 'ef' then --etc. end
Re: How to check the end of a string?
Yep, I meant that
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to check the end of a string?
Still sub, not gsub.Nixola wrote:Yep, I meant that
Help us help you: attach a .love.
Re: How to check the end of a string?
Oops, that's a typo
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: How to check the end of a string?
how do I truncate any excess chars?
like if i have
str = awasdawasd
how do I truncate every char after the 5th?
i've tried this
among other things but none of them have worked
like if i have
str = awasdawasd
how do I truncate every char after the 5th?
i've tried this
Code: Select all
if player[i].actionString:len() > 5 then
player[i].actionString:gsub(player[i].actionString:sub(6), "")
end
Re: How to check the end of a string?
Code: Select all
str = str:sub(1, 5)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Citizen
- Posts: 63
- Joined: Sun May 13, 2012 2:49 am
Re: How to check the end of a string?
yay thanks
Who is online
Users browsing this forum: Ahrefs [Bot] and 11 guests