- A search string I'd like to find in a text file
- The string will be an exact match of one full line in the text file, and one line only
- i.e., there are no duplicates in the file
- And if there were, only the first result is needed
- The files have potential to be thousands of lines long and maybe 150 chars per line, so not very large in the general scheme of things
- Function needs to return what line number of the file the search string can be found on
This works but it's a really a terrible way to do an array lookup. Even worse, the current code runs multiple times (reading the file from disk) instead of loading it once and doing a lookup in memory after-the-fact.
- Is there an easy way to map a text file into an array of lines without using a loop to read them in? Loop implementation would be easy, just wondering if there's a different way
- Once the text lines are in an array, is there built-in command or RegExMatch method that could be used without having to loop and manually compare every line the array?
- Or another idea: Would it be possible just to read the file contents into a single variable and be able to figure out which line of the file a string is on by finding a match and then counting how many line endings are prior to that? (Or something of that nature?)
- Maybe an associative array might work for one-time lookup if the indices were stored and the search string was used as the key?