• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help reading in data from a file

 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

So I am reading in a configuration file for a game. It holds data about the type of symbols the game has and the possible winning combinations of symbols. I wrote this program for a simpler configuration file where all of the symbols were on two characters. So I only had to read those two characters.

Now I have a line like this:

3 Silver7 Bell Bar : 2

And I need to read each of those strings into a separate variable. I'm hoping someone has ideas for a good way to do this. Also, please note that I am not using Java for this project(I know how to do this very easily in Java), I'm hoping to get some ideas as to what processes I can use.

Thanks
Hunter
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're not doing this in Java, then in what language age you doing it? It would be much easier to help you if you told us in which language you're programming...

For Java, one obvious way would be to use class java.util.Properties to load a *.properties file, which contains a key-value pair on each line (where keys and values are separated with an =).
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the company I am working for this summer has asked me to do this project in Python. I know this isn't a python forum; I'm just trying to get some ideas for determining how many characters to read into one variable.

so if I have something like:

Silver7 Bell Bar //I could look at this line and see that Silver7 is 7 chars long, Bell is 4 chars long, and Bar is 3 chars long
//so I would know to read in 7, then 4, then 3 chars

What I currently do is:


This only works for 2 characters however, I am looking for a more flexible solution since this program will be reading in a lot of these files.


Thanks
Hunter

(Note: the reason I posted this in the Java section was because the moderators there have been very helpful with my Java issues, I was looking more for ideas than language help)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic