Hi,
I am trying to count the instance of a double quote character in a text string.
I tried string.find, but it only returns the first instance and string.match or string.gmatch do not seem to be supported.
Any idea what I can do?
Hi,
I am trying to count the instance of a double quote character in a text string.
I tried string.find, but it only returns the first instance and string.match or string.gmatch do not seem to be supported.
Any idea what I can do?
Regards,
John
string.match and string.gmatch are from Lua 5.1, Girder uses Lua 5.0 which has string.gfind which should do what you want.
--Rob
ahh thanks. I'll try that one.
Regards,
John
Hi,
I tried this and is seems to do what I wanted for the first problem which is to count the total number of quotation marks in a string
Now I need to find within each string, the text between each quotation mark.Code:local mynum = 0 while mynum == 0 do for q in (string.gfind(MoviePath, '"')) do mynum = mynum + 1 end local MovieIndex = mynum/2 print ("total movies = "..MovieIndex) end
string.find gives me the first match, but I am not sure hot to iterate that over the entire string.
Any ideas on how to do that??
Thanks,
Regards,
John
You could do something like this
Note that I'm using [[ and ]] to delimit the pattern string here.Code:for q in string.gfind(s, [["(.-)"]]) do -- do something with the value end
--Rob
Thanks.
I am still struggling a bit. Perhaps a practical example would serve as a better way to express what I am trying to do.
I have a string that may look like this:
"M:\Video\A Scanner Darkly\VIDEO_TS\VIDEO_TS.IFO" "M:\Video\Amistad\VIDEO_TS\VIDEO_TS.IFO" "M:\Video\Backdraft\VIDEO_TS\VIDEO_TS.IFO" "M:\Video\Betterman, Vol. 1, The Awakening\VIDEO_TS\VIDEO_TS.IFO"
It contains a series of movie titles that are enclosed in pairs of double quotes " " which need to be retained and passed on down the line to another program later on. So what I need to do is take the string above, and create a set of variables based on the individual titles. Using this string above as an example:
Movie1 = "M:\Video\A Scanner Darkly\VIDEO_TS\VIDEO_TS.IFO"
Movie2 = "M:\Video\Amistad\VIDEO_TS\VIDEO_TS.IFO"
Movie3 = "M:\Video\Backdraft\VIDEO_TS\VIDEO_TS.IFO"
Movie4 = "M:\Video\Betterman, Vol. 1, The Awakening\VIDEO_TS\VIDEO_TS.IFO"
What might be helpful, (I think) is that I can format the string at the front end to have a delimiter say ## in between the titles, but I am still stuck on how to separate each title out. I am supremely confident it can be done in Lua, but I just have no idea as to how to go about it.
As always, any help is humbly accepted.
Regards,
John
The code above works for me with that data.
Actually, I tested it with
Code:for q in string.gfind(s, [["(.-)"]]) do print(q) end
--Rob
Hmmm, I'll try it again and see where I went worng. I thought I did the same thing with the print statement, but who knows.
Regards,
John
OK I see now.
I tried to integrate it into my similar for loop and broke it.
My first question is how does that work?
The trickery appears to be in the [["(.-)"]] part. What I see is a pattern, encapsulated in quotes, then (.-) which must mean everything in between?? Am I close?
At any rate, now I get each movie title, with the quotes stripped, so I restored those by changing it to this:
Now all I need is the way to create the variables. The first line should go to Movie1 variable, the 2nd to Movie2 etc. etc.Code:for m in string.gfind(MoviePath, [["(.-)"]]) do print('"'..m..'"') end
How would one go about that?
Thanks for your patience.
Regards,
John
OK, so I'm getting closer.
This prints out the titles followed by the name I'd like for each variable. The kicker is I don't know how to get a variable name to be assigned from another variables value. Is that even possible?Code:movievarnum = 1 for m in string.gfind(MoviePath, [["(.-)"]]) do movievar = "Movie"..movievarnum print('"'..m..'"') print (movievar) movievarnum = movievarnum+1 end
Last edited by johnp; February 19th, 2009 at 02:53 PM. Reason: bad typo
Regards,
John