I am attempting to parse input into three seperate Strings, namely:
String name;
String hull;
String port;
The input file contains submarines with name, hull number, and port i.e.:
USS Hyman G. Rickover [SSN-709] Norfolk, Virginia
USS Jacksonville [SSN-699] Norfolk, Virginia
It should resolve as follows if I do it correctly:
ex. USS Hyman G. Rickover [SSN-709] Norfolk, Virginia
name = USS Hyman G. Rickover
hull = [SSN-709]
port = Norfolk, Virginia
I am attempting the following to capture the name:
if (fileScanner.hasNext("[A-Za-z. ]")){
name = name + fileScanner.next() + " ";
}
Capturing the hull number
if (fileScanner.hasNext("[[[S][S][N][-0-9]")){
hull = hull + fileScanner.next() + " ";
}
And since the port should just be whats remaining on the line...
port = fileScanner.nextLine();
I'm sure I'm making some really dumb mistakes due to not understanding how to specify a pattern using characters such as -, ], space, etc.
Thanks for any input!
This post has been edited by jterry: 10 April 2009 - 12:31 PM

New Topic/Question
Reply




MultiQuote




|