3 Replies - 337 Views - Last Post: 22 January 2013 - 09:29 PM Rate Topic: -----

#1 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

How to read line per line in the text file with the second word only?

Posted 22 January 2013 - 08:38 PM

I have a text file name Mail order.

The order in the text file is:
101,3,49.99
103,5,2.75
101,8,49.99

the first column (101,103) is the item number, the second column is the quantity per item, and the third one is the price of each item number.

the instruction is to get the total sum of the quantity. in the given example the total sum is 16.
another instruction is to get the total of the price so first i have to add the 3 different prices and divide it to 3.

so the big question i had is how to read the text file line by line by the second word and third word only...

any help would be appreciated.. :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to read line per line in the text file with the second word only?

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10573
  • View blog
  • Posts: 39,148
  • Joined: 27-December 08

Re: How to read line per line in the text file with the second word only?

Posted 22 January 2013 - 09:04 PM

You can use the String split() method to break apart each line based on the commas. If there is more to this program, you should be thinking about designing a class to manage an Item.
Was This Post Helpful? 2
  • +
  • -

#3 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to read line per line in the text file with the second word only?

Posted 22 January 2013 - 09:21 PM

macosxnerd101 Thank you for your help but i think i cant focus on reading and using my analysis for now... Deadline of submission of this program is today.. .
However, i appreciate your help.. :)
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10573
  • View blog
  • Posts: 39,148
  • Joined: 27-December 08

Re: How to read line per line in the text file with the second word only?

Posted 22 January 2013 - 09:29 PM

It will be good supplemental reading for the future then! Good luck! :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1