简体   繁体   中英

What's the best way to split this text file?

basically i have this java assignment in which I need to take the following text file: https://drive.google.com/file/d/1NqWtApSHovOfSXzVCeU_GPtsCo_m6ZtJ/view?usp=sharing

The legend for the text file is here: E: did the elector result in promotion (1) or not (0) T: time election was closed U: user id (and screen name) of editor that is being considered for promotion N: user id (and screen name) of the nominator

V: vote(1:support, 0:neutral, -1:oppose), user id, time, screen_name

And create the following two methods:

  1. Given a user id, output the total number of times the user has voted to support or be neutral or oppose the candidate considered for promotion for all people the user has voted for collectively in all the elections.

  2. Given a user id considered for promotion, output the user id and screen name of the nominator. For multiple nominations, you will output all nominators. If the user is not nominated ever, output an appropriate message.

I'm really lost on how I should go about splitting the text file into pieces to help me obtain the information needed to create the two methods. Any insight would really be great

Basically you need to create different string reader loops that iterate over the text file line by line. Nobody here will do this for you because it´s to much work, and it´s your work!

Here´sa discussion about iterating-over-the-content-of-a-text

You can use the str.split() method. You write the point in the text at which you would like to split in the brackets. For example if you have the following;

String str "Hello world"; String [] arrayString = str.split (" ");// splits the string at the space for( String a:arrayString); System.out.println(a);

Output:

Hello

World

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM