Program text storage

insoniq

New Member
Hello,

What would be the best way to store text for a program.
The program I have in mind starts with a window with a table of contents.
When clicking on an item, it will jump to a separate window and display some text. The amount of text is somewhat large.
The program is similar to a Bible program, where you can jump to whatever verse you want.

Any ideas?
 

derez

Expert
Licensed User
Longtime User
You can use a binary file, which enables reading data randomly, by a pointer.
You will have to keep the positions of the pointer in an array so for every item in the list you'll have the position in the file and could read the data starting from that position.

I don;t know if its the best way but it is a possible solution.

You may have several files, a file per chapter, and then the verses in each file using the binary file.
 

Craig

New Member
There are a couple issues, actually. One is storage and one is compression.

You need to store the text in a way that allows you to access the pieces that you want. So if your text were a Bible, which is organized by book, chapter, and verse, you'd want to make sure you had an index containing the beginning position of each verse. The text might be in one file, and this index in another file.

If your text is large, you might want to consider some form of compression. Standard file compression algorithms aren't going to work well for you because you need to be able to jump into the middle of your text and start displaying from there. File compression requires that you decompress starting at the beginning.

A common and simple way to compress text so that it can be easily decompressed is to break it up into tokens and replace each unique token with an integer value. Then store your list of tokens and their values in a file and load it into an array when your program runs. (A "token" in this case would be a run of characters, separated by punctuation or spaces. So the tokens in this paragraph would be "A", "common", "and", "simple", etc. Replace all occurrences of "A" with 1, "common" with 2, "and" with 3, etc.)

These are the very basics. There's more to it than this, but I'm sure you'll discover the details as you begin implementing and using your program.

Craig
 

Smee

Well-Known Member
Licensed User
Longtime User
Wouldn't a simpler way be by using a combination of binary files and database for access to the key locations in binary files?

Regards

Joe
 
Top