Fastest way to know the contents of the latest line of a doc
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Fastest way to know the contents of the latest line of a doc
Hi all,
The subject of the message says almost all: What's the fastest way in LiveCode to know the contents of the latest line of a very long text document? And not just the last line, but the nth line?
best,
Daniel
The subject of the message says almost all: What's the fastest way in LiveCode to know the contents of the latest line of a very long text document? And not just the last line, but the nth line?
best,
Daniel
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Fastest way to know the contents of the latest line of a
Put the text in a field or variable (in this case a field named "NameOfTheFieldWithTheText").
Put the below code in a button and voila...
Regards,
Paul
Put the below code in a button and voila...
Code: Select all
on mouseUp
put line 9 of fld "NameOfTheFieldWithTheText" into tText
answer tText
put the last line of of fld "NameOfTheFieldWithTheText" into tText
answer tText
end mouseUp
Paul
Re: Fastest way to know the contents of the latest line of a
I mentioned "long" document to point to the case where the contents of the file are too long to be copied in memory. Of course you can just read the whole file and return the last line or the nth line. But in cases when such procedure is not advisable due to memory limitations, what's the fastest way to do it?
best,
Daniel
best,
Daniel
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Fastest way to know the contents of the latest line of a
Try this..
Tested it with a txt filetype.
Regards,
Paul
Code: Select all
on mouseUp
answer file "Please choose the file you want to work with"
put it into tFile
if there is a file tFile then
put tFile into tDocumentPathAndName
else
answer "No file captured"
exit mouseup
end if
get line 9 of URL ("file:" & tDocumentPathAndName)
put it into tText
answer tText
get the last line of URL ("file:" & tDocumentPathAndName)
put it into tText
answer tText
end mouseUp
Regards,
Paul
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Fastest way to know the contents of the latest line of a
Mr. Coollion's method seems pretty straightforward.
But just curious; what kind of document are you thinking of? The text portion of the Encyclopedia Britannica is only 100MB or so (my estimate). That is not even close to the memory limits of the usual computers these days.
Craig Newman
But just curious; what kind of document are you thinking of? The text portion of the Encyclopedia Britannica is only 100MB or so (my estimate). That is not even close to the memory limits of the usual computers these days.
Craig Newman
Re: Fastest way to know the contents of the latest line of a
Woah! Thanks. That's even better that I had expected.Code: Select all
get the last line of URL ("file:" & tDocumentPathAndName)
The only problem with this kind of Wunder answers is that they make me wonder how much I'm still missing. By the way, how does *that* works?
best,
Daniel
Re: Fastest way to know the contents of the latest line of a
Craig, I think you don't need to aproach the 100MB file to find yourself waiting too much time for the program to finits her duty when it comes to the situation where you need to consult many big files many times.dunbarx wrote:Mr. Coollion's method seems pretty straightforward.
But just curious; what kind of document are you thinking of? The text portion of the Encyclopedia Britannica is only 100MB or so (my estimate). That is not even close to the memory limits of the usual computers these days.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Fastest way to know the contents of the latest line of a
Hmmm.
Please explain what you are doing. I work almost never with external files.
In LC. I have a 3,000,000 line field with 150 MB of text. I can get any line in 10 ticks. If I put that dataset into an external file, and ask for the millionth line, it takes about the same time. What are you doing?
Craig
Oh yes.
Please explain what you are doing. I work almost never with external files.
In LC. I have a 3,000,000 line field with 150 MB of text. I can get any line in 10 ticks. If I put that dataset into an external file, and ask for the millionth line, it takes about the same time. What are you doing?
Craig
Oh yes.
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Fastest way to know the contents of the latest line of a
Does it? 150 MBs is a big malloc. It would be interesting to know the load time separate from the seek time.dunbarx wrote:In LC. I have a 3,000,000 line field with 150 MB of text. I can get any line in 10 ticks. If I put that dataset into an external file, and ask for the millionth line, it takes about the same time.
@Daniel: if you have a fairly confident sense of the max length of each line, you could use the seek command to seek to a location within the file that's safely far enough away from the file length to be sure to get a complete line, read at that point until EOF, and then get the last line of the resulting buffer in "it".
In fact, as I think about this you may not even need the extra "seek" statement, since IIRC the "read" command has as optional "at" param that can be used to set a starting offset within the file.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Fastest way to know the contents of the latest line of a
Once upon a time, I copied in a 4.7 Gb DVD the full decompressed text of Wikipedia (in spanish)
with the purpose of creating an Offline Wikipedia Reader using LiveCode.
After some failed tests and multiple experiments, I ended up splitting the big file in hundreds
of small text files. Each small text file was indexed and compressed. Accessing data with this method
resulted much, much faster than retrieving data from a single big file.
Al
with the purpose of creating an Offline Wikipedia Reader using LiveCode.
After some failed tests and multiple experiments, I ended up splitting the big file in hundreds
of small text files. Each small text file was indexed and compressed. Accessing data with this method
resulted much, much faster than retrieving data from a single big file.
Al