It is currently March 28th, 2024, 10:57 am

Case insensitive "if"

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

Case insensitive "if"

Post by LGP123 »

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: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Case insensitive "if"

Post by balala »

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: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Case insensitive "if"

Post by jsmorley »

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: 60
Joined: November 5th, 2016, 12:15 pm

Re: Case insensitive "if"

Post by LGP123 »

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

Re: Case insensitive "if"

Post by jsmorley »

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.
Post Reply