This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Sorting out Strings from a filereader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting out Strings from a filereader" Watch "Sorting out Strings from a filereader" New topic

Sorting out Strings from a filereader

harrie harrison

Joined: Jun 18, 2009
Posts: 6
I have to make an application that can read positions from a Draughts game and update it in a diagram (10x10 board).
Im running into a lot of problems and I would appreciate any help a lot.

the positions are stored in this format.

W7,13,50:B25,30,45 C. Blankenaar (1898)

everything after W goes in the white pieces textual display (jTextframe)
everything after B goes in the black pieces textual display (jTextframe)
the last part goes in another seperate jTextframe

I'm reading the files with a buffered filereader, and the next step is to separate the lines and put the positions in the correct display.
I would appreciate if it you could give me any pointers how to do this.

Thanks in advance.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

Harrie, please change your display name to meet the javaranch naming policy.

It doesn't seem to be a tough task to me. The method must parse the file using regex and then set the values to the text frames.

You can use a regex like W.*?: to get white coordinates and then use the split method to split the coordinates from commas. Same can be done for black coordinates. I hope I have understood the problem correctly ...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton

Joined: Sep 29, 2008
Posts: 12617

I think regex is probably overkill: the positions are delimited by the first space. Perhaps just grabbing up to the space, splitting on colon, then splitting on commas would be sufficient (taking the color character into account).
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Pretty random I know and possible off topic. But I thought Draughts was played on an 8 x8 board just like Chess.

I would parse each line into an object and put that into Lists, one for white one for black and one for other, that way you can release the FileHandle pretty quick.

I think regex would be over kill for this, just use the standard String methods.

You should be able to send each List to the required dispaly element.
harrie harrison

Joined: Jun 18, 2009
Posts: 6
Thanks for the advices, I figured out a way to do it. It aint pretty but it works.
I agree. Here's the link:
subject: Sorting out Strings from a filereader
It's not a secret anymore!