Computer Science Canada Reading from a .txt file (advanced) |
Author: | chipanpriest [ Wed Dec 21, 2011 8:31 pm ] | ||
Post subject: | Reading from a .txt file (advanced) | ||
Hey I need to make a program that reads information from a .txt file and outputs it on the screen and I have the basic understanding of reading/writing from .txt file. What I need ehlp with, is if I can get turing to read only part of the line because I have the name of the event and the date on the same line but I want them saved in separate variables. I have a picture here of the text file and also heres some code:
|
Author: | Tony [ Wed Dec 21, 2011 9:35 pm ] |
Post subject: | RE:Reading from a .txt file (advanced) |
: * reads in the whole line. You can read in one word at a time, if you don't use it. Alternatively you could read in the entire line, and then figure out what is what in it. Perhaps with the help of index |
Author: | Aange10 [ Wed Dec 21, 2011 9:37 pm ] | ||
Post subject: | Re: Reading from a .txt file (advanced) | ||
Before I begin to explain, do remember that there is more than one way to do things. I created a Database a little while back for a game (Maplestory) to hold all my data for items. In there I needed to hold a lot of variables in the same line. So when I decided how I was going to format my text file, I decided on a system like this:
After I decided on the format, I went through the file and took out all the data. (In the Turing Walkthrough, the tutorial File I/O explains how to do this. Aswell, the tutorial String Manipulation explains how to do what I'm about to talk about) Once I had all the data, I searched through each string. Now lets say I wanted to get the name. I'd go through the string and find the first [. Then I'd go through and find first ]. Finally, I'd assign the name to whatever was between [ and ]. Then I was able to do that for everything else. Likewise, I was able to easily get information in pieces. (I'll attach the Database if you'd like to see it. Warning: It's an old project, and the code is on the bad side. Though running the program will show you it in function, the code is rather messy and inefficient.) |
Author: | chipanpriest [ Wed Dec 21, 2011 10:27 pm ] |
Post subject: | RE:Reading from a .txt file (advanced) |
haha thats funny cause i actually still play maplestory xD |
Author: | chipanpriest [ Wed Dec 21, 2011 10:33 pm ] |
Post subject: | RE:Reading from a .txt file (advanced) |
and thats actually sick. so you enter in items that you want to keep prices for so its kind of like a storage place for everything you enter in? |
Author: | Aange10 [ Thu Dec 22, 2011 1:54 am ] |
Post subject: | RE:Reading from a .txt file (advanced) |
Pretty much. I still play, too, just not much. I was going to add a remove button, and an edit button, but I have yet to. (You might notice the pictures in the file) I may go back to developing the program, but I'd be rewriting it. It's high innefficient, and quite stupid, in all honesty. Anyways, was your question answered? |