CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Scanner class

  1. #1
    Join Date
    Oct 2004
    Posts
    37

    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.

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  3. #3
    Join Date
    Oct 2004
    Posts
    37

    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

  4. #4
    Join Date
    Apr 2003
    Location
    Los Angeles area
    Posts
    776

    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
  •  





Click Here to Expand Forum to Full Width

Featured