[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: How to extract a word at a given position in a string?
- From: Benoit Germain <bgermain@...>
- Date: Thu, 10 Mar 2011 12:37:48 +0100
> -----Original Message-----
> From: firstname.lastname@example.org [mailto:email@example.com]
> On Behalf Of Michal Kolodziejczyk
> Sent: Thursday, March 10, 2011 10:11 AM
> To: firstname.lastname@example.org
> Subject: Re: How to extract a word at a given position in a string?
> > What I am currently doing is even more brutal than that: I know that
> > look for a file path. So I iterate over all words, and check for each
> > them if the file exists. If true, I found a file and I can act on it
> > But there is surely a better way…
> OMG, for each string you make a system call :( Your hard drive does not
> like this for sure.
[BG] I've improved on this: I know that I print only absolute file paths, so I check for file existence only on words with a '\\':
if selectedLine then
for segment, sep in string.split( selectedLine, "[ \t\n]") do
-- let's see if this looks like a file name before actually checking its existence
if string.find( segment, "\\", 1, true) then
local filemode = lfs.attributes( segment, "mode")
if filemode == "file" then
fileUnderCaret = segment
After all, clicking on the line is good enough for me, I never have more than 1 file name in it. Somehow I find it more elegant than extracting the word character by character and then concatenating this character list.