0

do you know how to search for an item in an table which is not completed ?

items = {"0x10_first_one.json", "0x20_second_one.json", "0xFF_thirs_one.json"}

local function locate( table, value )
  for i = 1, #table do
      if table[i] == value then 
          print(i) 
          return true 
      end
  end
  print( value ..' not found' ) 
  return false
end

locate(items, "0x10" )

I know that I ned to search for "0x10_first_one.json" to get an 1 back. But i usually do not have the full string. I just have "0x10". How can I search for it that it also gives 1 back.

Thanks

Search for an item in a Lua list

Glupschi
  • 215
  • 1
  • 9

1 Answers1

0

I found the solution by myself.

function locate(table, value)
  for i = 1, #table do 
      test = tostring(table[i])
      if string.match(test, value) ~= nil then 
          print(i)
      end 
   end 
  end 

  locate(t, "0x10[_%w]+.json")
Glupschi
  • 215
  • 1
  • 9