Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:35:54+00:00 2026-05-22T20:35:54+00:00

Java Scanner has a next() method, which read the next token from a stream,

  • 0

Java Scanner has a next() method, which read the next token from a stream, where a token is something separated by delimiters (by default the delimiter is any whitespace character, including tab and new line).

How can I do this with C#/.NET? A stream in C# has Read() and ReadLine(), but they don’t have a notion of whitespace or custom delimiter. I can read the whole line and then use string’s Split() method, but that means I have to read the whole string first (as opposed to next() which only read the next token).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:35:55+00:00Added an answer on May 22, 2026 at 8:35 pm

    Well, you could read a character at a time, and check whether it matches the delimiter. I believe that StreamReader keeps a buffer anyway, so it shouldn’t have much performance cost (i.e. it won’t hit the disk each time you read a character). You can just keep a StringBuilder of “the token so far” and keep going until you hit a delimiter, at which point you return the token.

    Alternatively, for performance reasons, you could read a chunk at a time, and scan through the array of characters looking for the delimiter, then build the string when you’ve found it. Keeping the state consistent will be significantly trickier than just using a StringBuilder and reading a character at a time, but if this is critical to performance then it might be worth it.

    I wouldn’t try to emulate all of what Scanner does – just write the bits that you need. You might want to consider implementing this as an IEnumerable<string> using iterator blocks for convenience. You’d probably want to pass in a Func<TextReader> rather than the TextReader itself, so that the iterator block can close the reader appropriately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java has a convenient split method: String str = The quick brown fox; String[]
Java has the thread dump which is triggered by a signal 3 sent to
Purpose: Obtain the public method signature(return value,parameter,method name) from java bytecode files. I am
In java, what code do I need to get from http://www.mysite.com/text.txt to a Scanner
I wrote a Course class that has constructors that read from text and binary
Java has generics and C++ provides a very strong programming model with template s.
This example demonstrates using Scanner to read a file line by line (it does
I am creating a GUI using Java. This GUI launches a program from the
Anyone that could help me with the java.util.Scanner class? I can't figure out exactly
I'm trying to parse a section of a large file with Java's Scanner library,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.