Hi eveyone, :twisted:
I have a problem about Scanner class which make me really annoyed
I could not find the meaning of useDelimiter(
method.Besides
I do not understand why it is used and when
If anyone inform me , I will be happy
Thank
Mer
http://www.devplug.com
IchBin - 16 Jan 2006 08:21 GMT
> Hi eveyone, :twisted:
> I have a problem about Scanner class which make me really annoyed.
[quoted text clipped - 5 lines]
> Mert
> http://www.devplug.com
You can change the delimiter that is used to tokenize the input,
through the useDelimiter method of Scanner. You can pass in a String or
a java.util.regex.Pattern to the method. See the JavaDocs page for
Pattern for information on what patterns are appropriate. For example,
you can read the input one line at a time by using the newline character
(\n) as a delimiter. Here is a readFile() method that uses a newline
character as the delimiter:
private static void readFile(String fileName) {
try {
Scanner scanner = new Scanner(new File(fileName));
scanner.useDelimiter(System.getProperty("line.separator"));
while (scanner.hasNext()) {
System.out.println(scanner.next());
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Roedy Green - 16 Jan 2006 08:48 GMT
On Mon, 16 Jan 2006 01:37:04 -0600,
m_ozkaya@ug.bilkent.edu-dot-tr.no-spam.invalid (mert) wrote, quoted or
indirectly quoted someone who said :
>Hi eveyone, :twisted:
>I have a problem about Scanner class which make me really annoyed.
[quoted text clipped - 5 lines]
>Mert
>http://www.devplug.com
from the javadoc
The scanner can also use delimiters other than whitespace. This
example reads several items in from a string:
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();
prints the following output:
1
2
red
blue
Looks like it is much like split where you provide a pattern to
describe your delimiter, which is otherwile white space.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.