Page 1 of 1
Case insensitive "if"
Posted: May 24th, 2017, 10:05 am
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
Re: Case insensitive "if"
Posted: May 24th, 2017, 11:17 am
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.
Re: Case insensitive "if"
Posted: May 24th, 2017, 11:18 am
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....
Re: Case insensitive "if"
Posted: May 24th, 2017, 11:28 am
by LGP123
Thank you very much guys
It's working well.
Re: Case insensitive "if"
Posted: May 24th, 2017, 12:00 pm
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.