File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to get manageable arrays to work with

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So wouldn't you want to split the string "2, A110, D20" into the three strings "2", "A110", and "D20"?
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12017
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so do it a piece at a time. split it by commas, and then re-split the fields into the sub-components.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Now I have added the code to split the itinerary twice.

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic