Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / parsing text from file (Matrix) in edit (BlueGUI)

Author
Message
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 29th Sep 2011 16:28 Edited at: 29th Sep 2011 16:31
Hello everybody,

I wish to parse text from a file (Used Ian M's Matrix plugins) to my edit box (made with bluegui) but I have a little problem here. I need to add chr$(13) to proceed to the next line but I do not want that for the last line of the file.

This is the code:



My idea was to remove the last (empty) line when the datafile has reached it's end but instead of doing so, it makes a square character. The code used for that is commented out.

I do need this for my script editor else it would simply add empty lines to the file every time I save it.

Anybody got a solution? Thanks!!

Regards Sph!nx
http://www.mental-image.net
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 29th Sep 2011 17:30 Edited at: 29th Sep 2011 17:52
Not only chr$(13), but have you also added it to parse chr$(10) ?

The Character of LF ( Line Feed or also known as NL = New Line ) is Decimal of 10 and in HEX its 0A.

Here is a free HEX editor, look for yourself.

http://www.hhdsoftware.com/free-hex-editor

Here is an ASCII chart :

http://www.asciitable.com

Also, if you want to prevent the last line from going any further, parse it ahead of time before saving it. Its kind of like adding an End Of File ( EOF ) to it. And what your looking for is HEX 0D ( Decimal 13 ) and HEX 0A ( Decimal 10 ) . ( 0D = CR / Carriage Return and 0A = New Line ) Just remove those at the end of your last line.

"Life is like a box of chocolates.. eat it before it melts."
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 29th Sep 2011 18:49 Edited at: 29th Sep 2011 18:54
Thanks for your quick reply!

Quote: "Not only chr$(13), but have you also added it to parse chr$(10) ? "

Nope, will try! Edit: Tried it... does the same thing as chr$(13).

What did you mean by this exactly?
Quote: "Also, if you want to prevent the last line from going any further, parse it ahead of time before saving it."

...do you mean something like write it in the background before parsing and if it passes a 'check if the file has ended'-check then parse it? This might work.

Regards Sph!nx
http://www.mental-image.net
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 29th Sep 2011 20:01 Edited at: 29th Sep 2011 20:02
Quote: "Tried it... does the same thing as chr$(13)."


I was actually meaning for you to look for both of those together. Not one or the other, but look for both. They will always be in the same order from what I have tested. ( 13 first then 10 after that )

In assembly language this is what we use for the NEXT LINE. Both together IN that order is how it knows its at the end of the line.

You'll see an example in assembly language :

db test "this is a test",13,10

Point being, look for both together. and yes, check your final output by parsing it FIRST before you output it to a file or where ever your wanting to put it.

"Life is like a box of chocolates.. eat it before it melts."
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Sep 2011 20:12
Actually, it's easier to come up with a solution if instead of thinking of the carriage return as a line-end, that you think of it as a separator - just add the separator before you add your new string for every string except the first one.



JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 29th Sep 2011 22:39
That's brilliant IanM. I am so used to the old way of doing things sometimes.

One other suggestion I was going to add is find out how many characters ( bytes ) total in your whole text and then parse to the last couple bytes and see if the 13 or 10 or any other character you do not want is there. If they are, trim them.

"Life is like a box of chocolates.. eat it before it melts."
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 30th Sep 2011 16:19
Thanks to the both of you!

IanM, I see I was in the right direction but my check for the end of the file was after writing it and I see in your example it's best to check it before writing the lines.

Afraid I won't have the time today to revise and test my code but later this weekend I will. I'll post how things went. Thanks again!

Regards Sph!nx
http://www.mental-image.net
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 2nd Oct 2011 16:50
Yeah, I got it!

Solution:
Well, it did the same thing as before, it added a crlf$() at the end as well. BUT, as IanM demonstrated, he made a single string before using it further. Because it was a single string and not individual strings I could easily trim the last crlf$'s from the string and then write it to the edit.

Regards Sph!nx
http://www.mental-image.net

Login to post a reply

Server time is: 2026-07-10 06:08:01
Your offset time is: 2026-07-10 06:08:01