File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Trying to get manageable arrays to work with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trying to get manageable arrays to work with" Watch "Trying to get manageable arrays to work with" New topic
Author

Trying to get manageable arrays to work with

Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hello, I have a file that needs to be read in and I would like to capture each line in a nicely delimited fashion. I need to be able to go back to the data, fetch it and use some logic on it. Here is what I have so far:


My output is
[A, B, 5, 0, 0, , B, C, 4, 0, 0, , C, D, 1, 0, 0, , D, E, 6, 0, 0, D, E, 8, 0, 0, , E, B, 6, 0, 0, , B, F, 4, 0, 0, F, D, 1, 0, 0, , D, C, 8, 0, 0, , C, E, 2, 0, 0, , E, B, 3, 0, 0]
[2, ,, , A, 1, 1, 0, ,, , D, 2, 0, 4, ,, , A, 1, 1, 0, ,, , D, 2, 0, 2, ,, , D, 2, 0, ,, , A, 1, 1, 0, 1, ,, , A, 4, 5, ,, , C, 5, 4, ,, , D, 1, 0, 0, ,, , B, 0, 1, ,, , A, 5, 0, ,, , F, 2, 0]


I guess first of all I should start with saying that I do not understand whay all the additional commas in the second printout and ask if there is a cleaer way to do all this. Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

By "the second printout" I'm going to guess that you meant the second line of your output. And I expect that if you look in the input file ("itinerary.txt") you'll find that the output doesn't have extra commas, it just has commas which are copied from the input to the output.

As for what you should do instead, I'm afraid I have nothing to say. I wouldn't have called your output "nicely delimited" but on the other hand you seem to be satisified with at least the first line. So that means I don't know what you're trying to achieve with that code.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thanks Paul. What I need to do with this code is read from itinerary.txt and match destinations against the airport/mileage combinations in airports.txt to see if there is a feasible route. So from itinerary.txt, "2, A110, D20" is a reference to route AD<some mileage>. I need to search airports to see if there is an AD??? pairing first to determine if there is even that route.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

So wouldn't you want to split the string "2, A110, D20" into the three strings "2", "A110", and "D20"?
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hi Paul, I do need to split the string, however I am having trouble determining how to do that at precisely the points I need to. So "2, A110, D20" would need to be split into "2" for number of travelers, "A" for departure airport, "110" for number of miles to it from home, "D" for arrival airport and "20" for number of miles to destination. Thank you.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

so do it a piece at a time. split it by commas, and then re-split the fields into the sub-components.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hi Fred, I have added the following code:



but can't figure our how to parse a charintintint string into constituent char and ints. Thanks.
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
OK, Now I have added the code to split the itinerary twice.

Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
I am having trouble creating an array that will hold all the values of splitting itineraries. I have test2 declared globally and I'm trying to use it to hold ALL the lines read in and split by br. Any help appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to get manageable arrays to work with