Search tables for number of occurrences?
Search tables for number of occurrences?
I'm looking for a way to search through a table and return how many times a string appears in any key in that table, as well as each key it appears in. For example, I have a table with the values "applepie", "banana", "cherrypie", and "orange". I want to search that table for each occurrence of "pie", return each string it appears in, "applepie" and "cherrypie", and return the number of times it appears, 2. Is this possible or would it be prohibitively complex?
Re: Search tables for number of occurrences?
That's a pretty simple script. You simply iterate over the keys and do a string search on them.
Re: Search tables for number of occurrences?
This goes through the whole table, checks if it finds the string "pie" in each entry, and if it does, adds 1 to a counter and adds the item to another table, that only contains the pies. In the end it prints the number of pies and displays our new list.
Re: Search tables for number of occurrences?
Awesome, thank you two. I had something similar done already but I was using the wrong syntax for the foor loop like an idiot. Oh well.