Announcement

Collapse
No announcement yet.

Custom Function inTable. Please help me improve it.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Function inTable. Please help me improve it.

    Hello all,

    I've made a function called inTable. It checks if a value is in a table. Returns true if it is. false if not:

    Code:
    function inTable(table, value)
    	local i = "";
    	local v = "";
    	for i, v in pairs(table) do
    		if value == v then
    			return true
    		end
    	end
    	return false
    end
    Now, i want to improve it a bit. I want to be able to use placeholders like * and ?. Is this possible? Just the same placeholders like you have in File.Find

  • #2
    Use patterns. Check the 5.4.1 - Patterns section in the attachment.

    Lua 5.1 Reference Manual.zip

    Comment


    • #3
      Thank you for your answer. but i can't get my head around it.

      I've tried this as an example test pattern: ".+.txt$"
      I searched in the string "backup.txt" and "backup.txt.bat"

      It should match backup.txt but not backup.txt.bat
      But it doesnt match backup.txt

      how should i understand my pattern ".+.txt$"?
      Like this? look at the end of a string and search for .txt
      Select any character (.) one or more times as many as possible.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎