So i have several lines of data in a .txt file. I need to read them in and split up each segment into separate variables.
the data looks like this:
9#H#Hockey Player 5#1#Red Wings#Goalie#32#600000#0
So i have several lines of data in a .txt file. I need to read them in and split up each segment into separate variables.
the data looks like this:
9#H#Hockey Player 5#1#Red Wings#Goalie#32#600000#0
Thanks for starting a new thread. Now, you'll need to give all your requirements and problems, such as why a split("#") won't work. Best of luck.
I'm guessing you want to use the # to separate the text?
The Strings split method might be of use to you.
EDIT: sorry missed the post above.Code:public String[] split(String regex)
Splits this string around matches of the given regular expression.
Ok so i can get it to split now but im now stuck on how i would assign the variables
This doesn't tell us much. You assign them in what ever way works best for you. Without more information, that's the best answer you'll likely get.
You might want to read this link: How To Ask Questions The Smart Way
It will help you to ask questions that can be answered in a way that may helpful to you -- for instance how to provide enough information that will allow others to know what your problem is. I know that the site has helped me in the past, and I read it about once a month.
Oh im sorry.
What i ment was i can read it all in split it up to what i want and it will print out each segment that i need. Im just not sure how i would be able to store each value as the player number, player name, position etc. Between each # is a variable that needs to be stored
would i assign them in the while loop is my question
Probably not since you're not assigning them to an array. Likely you'll have to assign them one at a time, either that or if Player has a constructor that takes either the individual data or the data array, then do it that way.
but what are you using to read the data?
if Scanner, then set delimiter and use nextInt, next, etc...
such as:
*use loop where necessary.Code:int playerNumber;
*loop(){
playerNumber = scanner.nextInt();
...
}