|
-
November 30th, 2005, 05:18 PM
#1
Scanner class
Hi, got a question about Scanner class that comes with java sdk 1.5.
Scanner getin=New Scanner(System.in);
String text=""
text=getin.next();
getin.next() takes only complete word, but how can i take separate words to
readed in text variable. If i enter "New York" this scanner .next() cant take it.
Thanks.
-
November 30th, 2005, 05:26 PM
#2
Re: Scanner class
What do you use as delimiter? If you press enter between each 'city name', then maybe you can use Scanner.nextLine().
- petter
-
December 5th, 2005, 09:47 AM
#3
Re: Scanner class
I ended up using Scanner class, and created new object only for .nextLine() method,
maybe not best solutionbut now i dont need to worry about jumping over lines.
By the way whats real usage of this nextLine() method doesn't seem to be very handy to use. Why to jump over lines that way
-
December 5th, 2005, 08:33 PM
#4
Re: Scanner class
Normally, a scanner is the first part of a compiling system. It is meant to be used to parse a document into tokens that a compiler might interpret. I have found this class to be very useful on occasions. You probably didn't play with the match method which allows you to apply regular expressions to the current line. That is its most valuable function I think. If you are only parsing the beginning of a line then the nextLine is an easy way skip past the remaining line.
"The Chicken and Rice MRE is not a personal lubricant."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|