tosfera Posted October 4, 2013 Posted October 4, 2013 hey guys, I'm trying to make some systems with mysql etc, its not that important. Don't even want to waste time talking about it, but the story is as following; I got a function thats accepting 4 parameters; dbTable, dbField, dbValue, dbId. The dbTable will hold the name of the table where the single insert will be fired into. But there has to be a where clause. Now, I can add another parameters ( dbIdName ) to use in where where clause ( where dbIdName = dbId ) but I don't want that. The name of my table is; Vehicles, the name of the primary key is; VehicleId. You can see the difference. So, I was thinking about using gsub to replace the s out of Vehicles and add Id to it. It wont be any problem, BUT! What if I have a table that's called; Users? There will be 2x an s which will both be replaced. The gsub allows you to limit the amount of letters replaced, starting off at the first byte. which will be the first s in users. My question is, is there anyway to revert the gsub function to start counting from the end of the string? maybe flip the string ( Users => sresU ) gsub with a limit of 1 and then flip it again? Thanks edit1; close the thread, I got it working with string.reverse, string.gsub. For those that are interested in the code; function getPrimaryKey ( dbTable ) return string.reverse ( string.gsub ( string.reverse ( tostring ( dbTable ) ), "s", "", 1 ) ); end
Recommended Posts