It sounds like you want to store both normal and lowercase versions of the string, i.e. something like
local sLower = string.lower( event.target.text ) -- see if the entry exists if cluthaTable[sLower] then print( cluthaTable[sLower].name.." = "..cluthaTable[sLower].id ) -- if it doesn't exist, then create it else cluthaTable[sLower] = { name = event.target.text, id = 24 } end
Still, you’d need to determine how you give out those id’s, and as nick already said, you may run into issues if people mistype those entries.
Having worked on things like this in the past, I must advice against your current approach. That is, if I’ve understood your approach correctly. The safest way is to create a dedicated function for creating new table entries (and only allowing specific people access to it). This should be completely separate from where you search for information.
Then, you should create a predictive (but not really) search function, case and point:
local t = {} t["electric dance llc"] = { name = "Electric Dance LLC", id = 1 } t["electrics supreme"] = { name = "Electrics Supreme", id = 2 } t["electronics n' stuff"] = { name = "Electronics n' Stuff", id = 3 } t["elections for all"] = { name = "Elections for All", id = 4 } local defaultField, lowerS, match local lower = string.lower local len = string.len local function textListener( event ) if ( event.phase == "editing" ) then lowerS = lower( event.text ) match = false print( "\n----------------\npossible matches:" ) for i, j in pairs( t ) do if i:sub( 1, len(lowerS) ) == lowerS then print( j.name ) if not match then match = true end end end if not match then print( "0 matches found" ) end end end defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener )
The textListener function will go through table t after every keystroke and see if the initial characters of the inputted string matches with one or more of the entries. Then it prints out those possible matches.
Now, this is just an example and you’d want to create display objects of the top 3-5 matches that the user can then tap to directly select a company (or they can just keep on writing and hope that they don’t mistype it, because any and all mistyped entries need to be ignored). This makes it faster, safer and more convenient for the users. You could additionally have a list of “the most commonly searched companies” available for the users to directly tap as well without typing anything in.
The truth of the matter is that people make mistakes. Tired, hungry or inattentive people make even more mistakes. Offices are full of people like these, and when people in offices make mistakes, they cost money. So, best to try to prevent as many and as serious mistakes as possible.