Trim newline-seperated string to last 10 lines?

For questions about using Classic.

Post » Wed Dec 02, 2009 8:01 pm

Every few seconds I want to load a newline-separated text file to a text box, but I only want to display the last few lines. This wouldn't be a problem if I could scroll the text box, but I can't (or don't know how to), so... can anyone help? :D
B
2
S
2
G
3
Posts: 193
Reputation: 1,636

Post » Wed Dec 02, 2009 10:58 pm

You might be able to use GetToken(), and NumTokens()

For example, let's say you're storing the file contents in a global named file_contents, i.e., Global: Set 'file_contents' to File.LoadFileToString(AppPath & "file.txt")

Well, NumTokens(global('file_contents'),NewLine) should tell you how many lines there are in the file_contents global.

So, you could possibly do this:
For "loopname" from NumTokens(global('file_contents'),NewLine) - 10 to NumTokens(global('file_contents'),NewLine):
with the action: System: Set 'somevar' to global('somevar') & GetToken(global('file_contents'),LoopIndex,NewLine)

And set your text box to show global('somevar')

Or you could clear the text box's text first, and instead have your action set the text box's text to: Editbox.Text & GetToken(global('file_contents'),LoopIndex,NewLine) ..if it's an editbox.

I hope I made enough sense. I'm tired.
B
3
S
1
G
3
Posts: 82
Reputation: 1,189


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests