-1

How to implement search for a part of a string without letter case

a = {["hello"] = 1,["Hello"] = 2}

for i in pairs(a) do
if string.find(i, "h") then print(i) 

--should be "hello" and "Hello"

Oka
  • 23,367
  • 6
  • 42
  • 53
NEKKITIS
  • 15
  • 1

1 Answers1

3

Use pattern character sets, and include both cases.

local a = {
    ["hello"] = 1,
    ["Hello"] = 2
}

for i in pairs(a) do
    if string.find(i, "[hH]") then
        print(i)
    end
end

For something more robust, see Case-insensitive Lua pattern-matching.

Oka
  • 23,367
  • 6
  • 42
  • 53