I have a file path, gotten from the __FILE__ macro, and I want to extract 2 pieces from it.
The format is: /some/path/to/a/file/AAA/xxx/BBB.cc. I want the AAA and BBB path. xxx is generally src, inc, tst, etc, and the file extension is generally .cc, but not guaranteed.
I know I can use string.find() or even splitting the string into an array on the / character, but neither seem efficient, given the number of searches that would be needed. I thought about sscanf and feel that is probably the best approach, however, I have not been able to define the format such that it will skip the majority of the beginning and get the pieces I need. How could I use sscanf to do this, or is there a better way?
Thanks for the help.
Use
rfind, so that you can start at the end and work backwards: