0

I have the same problem as lua string.find not recognising substring but I've tried the suggestions in it to no avail.

                    local share_index = master_table[line_index]
                    local string_dump = table.concat(holding_table," ")
                    local string_search_start = string.find(string_dump,share_index)

                    holding_table[line_index] = (master_table[line_index])

                    print ("share index:"..share_index..":")
                    print ("string_dump:"..string_dump..":")
                    print ("string_start:",string_search_start)
                    print ("string_end:",string_search_end)
                    string.find("mypattern", "pat")
                    print(share_index:byte(1,-1)) 
                    print(string_dump:byte(1,-1)

This section of code is supposed to dump strings from a table and check and see if the currently processing string is found in what's dumped from the table. It always returns nil. I've converted it to byte codes to see if anything is hiding and there's nothing there. I've trimmed the whitespace just to be sure (not shown here, I removed it as a it didn't work.) I've manually added plain text for "my pattern" and "pat" and that's not found either.

I have no idea what's wrong here. It has to be something simple and obvious but I'm just not getting it. Any help is appreciated.

  • Can you include an example values of your `holding_table` and `share_index ` – Nifim Jan 30 '20 at 17:58
  • bobs_home_dir cheese-please MP3_Collection each of the above would be in separate element in the table. The problem is when I have two occurrences of the same directory, I'm doing double-processing. I'd like to be able to check to see if the directory is table first; Doing a string.find seemed like an easy solution, but this is making me crazy – Argh Tastic Jan 30 '20 at 18:10
  • your problem is you have values in your string that make them not good as a pattern. specifically `cheese-please` has a `-` in it. – Nifim Jan 30 '20 at 18:31
  • 1
    `string.find(string_dump, share_index, 1 true)` – Egor Skriptunoff Jan 30 '20 at 18:48

1 Answers1

0

Thank you, Egor and Nifim. This is what I was looking for.

I used the response Egor provided for the fix...note that Egor was missing a comma. So te final looks like:

string.find(string_dump, share_index, 1, true)