It is currently June 26th, 2019, 12:41 am

Case insensitive "if"

Discuss the use of Lua in Script measures.
User avatar
LGP123
Posts: 57
Joined: November 5th, 2016, 12:15 pm

Case insensitive "if"

LGP123 » May 24th, 2017, 10:05 am

I'm making a little skin that use lua scripting and I would like to know is there where any ways to have a "if" test that is case-insensitive. Something like this :
if Var1 (=case insensitive test) 'string' then
User avatar
balala
Rainmeter Sage
Posts: 8312
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Case insensitive "if"

balala » May 24th, 2017, 11:17 am

Yeah, there is: if string.upper(Var1) == 'THE-UPPERCASE-STRING' then. Here the Var1 variable is converted to uppercase (by the string.upper(Var1) function), then this string is compared with the THE-UPPERCASE-STRING variable. If you have the same strings, no matter which characters of the Var1 variable are upper- and which ones are lowercase, the if condition will be true.
Similarly you can use the string.lower(Var1) function, to convert the uppercase characters, to lowercase.
User avatar
jsmorley
Developer
Posts: 19269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Case insensitive "if"

jsmorley » May 24th, 2017, 11:18 am

if string.lower(Var1) == 'hello world' then

or if you prefer:

if string.upper(Var1) == 'HELLO WORLD' then

Edit: Balala beat me again....
User avatar
LGP123
Posts: 57
Joined: November 5th, 2016, 12:15 pm

Re: Case insensitive "if"

LGP123 » May 24th, 2017, 11:28 am

Thank you very much guys :)
It's working well.
User avatar
jsmorley
Developer
Posts: 19269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Case insensitive "if"

jsmorley » May 24th, 2017, 12:00 pm

LGP123 wrote:Thank you very much guys :)
It's working well.
Glad to help. BTW, for completeness sake:

if Var1:lower() == 'hello world' then

also works.