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 512451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:19:16+00:00 2026-05-13T07:19:16+00:00

I have a text file named C:/test.txt : 1 2 3 4 5 6

  • 0

I have a text file named C:/test.txt:

1 2 3 4
5 6

I want to read every number in this file using StreamReader.

How can I do that?

  • 1 1 Answer
  • 1 View
  • 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-13T07:19:17+00:00Added an answer on May 13, 2026 at 7:19 am

    Do you really need to use a StreamReader to do this?

    IEnumerable<int> numbers =
        Regex.Split(File.ReadAllText(@"c:\test.txt"), @"\D+").Select(int.Parse);
    

    (Obviously if it’s impractical to read the entire file in one hit then you’ll need to stream it, but if you’re able to use File.ReadAllText then that’s the way to do it, in my opinion.)

    For completeness, here’s a streaming version:

    public IEnumerable<int> GetNumbers(string fileName)
    {
        using (StreamReader sr = File.OpenText(fileName))
        {
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                foreach (string item in Regex.Split(line, @"\D+"))
                {
                    yield return int.Parse(item);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file named test.txt I want to write a C program
Hi I am trying to read a plain text file named test.txt from my
I have a text file named num.txt who's only contents is the line 123
I have a test script, that generate txt file with answers. And have 2
I have a text file which contains something like this: Hello, my name is
I have a text file that contains a list of filenames, minus the extension,
I have text file with some stuff that i would like to put into
I have Text file that contains data separated with a comma , . How
I have text file with some text information and i need to split this
I have a file named gcc.exe and I have a php page... I want

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.