01 | function theissue(l) |
02 | --yea basically this wont detect if the string is upper case or lower case i have no idea what im doing wrong here |
03 | local typ = "" |
04 | if string.upper(l) then |
05 | typ = "upper" |
06 | else |
07 | typ = "lower" |
08 | end |
09 | print (typ) |
10 | end |
Basically it wont detect if the string is upper case i dont know what i am doing wrong but apparently im doing something wrong i guess
string.upper()
only just returns the string with all the letters in uppercase, it doesnt return if theres uppercase nor lowercase letters inside the string. you'd use string.match()
and the %u pattern.
1 | local function theissue(L) -- use local functions |
2 | local typ |
3 |
4 | if string.match(L, "%u" ) then |
5 | typ = "upper" |
6 | else |
7 | typ = "lower" |
8 | end |
9 | end |
though this would only detect if theres a letter thats uppercase, not the entire string. if you'd want to find out if the entire string is uppercase then you could loop through it.
01 | local function theissue(L) |
02 | local typ = "upper" |
03 |
04 | for letter in string.gmatch(L, "%a" ) do |
05 | if not string.match(letter, "%u" ) then -- if it finds a lowercase letter |
06 | typ = "lower" |
07 | break -- breaks the loop |
08 | end |
09 | end |
10 |
11 | print (typ) |
12 | end |
the %a pattern is every letter in a string.
Here's a function to check if it is uppercase.
1 | function IsUpper(s) |
2 | return (s = = string.upper(s)); |
3 | end |