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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:23:43+00:00 2026-06-01T20:23:43+00:00

I am attempting to take numbers (characters 0-9) in from a file and store

  • 0

I am attempting to take numbers (characters 0-9) in from a file and store them in memory.

Lets say we have a string called “register” (and can only (must) hold 5 chars max) and the register string will take in numbers that are read from the file so for example:

File1.txt:

The house number is 10 and the price is 4000 and 3.

So the register would be filled with the following: “10400”

Some logic would then be performed against the string and then the first char would be removed from string and everything would shift 1 to the left and another char (number) from the file would be added e.g.:

04000

and then…

40003

Hopefully somebody could shed some light on this and provide some ways of achieving this 🙂

  • 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-06-01T20:23:44+00:00Added an answer on June 1, 2026 at 8:23 pm

    OK…

    First, a FileStream and associated StreamReaders will allow you to read from the file in pretty much any format you desire. This will be important because your specific algorithm will determine the retrieval method.

    Boiling it down, you want to read characters from the file, and when that character is a number, store it in the register, continuing in this manner until you have five number characters in the register. Then, you’ll do some logic that results in the first number no longer being useful, so you truncate it and get the next value.

    How about something along these lines?

    var register = new StringBuilder();
    
    using(var stream = File.Open("File1.txt"))
    {
       bool ended, fileEnded;   
       int buffer;
       while(!ended)
       {
          while(register.Length < 5 && !fileEnded)
          {
             buffer = stream.ReadByte();
             if(buffer == -1)
             {
                fileEnded = true;
                break;
             }
    
             var myChar = (char)buffer;
             if(Char.IsNumber(myChar))
                StringBuilder.Append(myChar);
          }
    
          //at this point you have 5 characters in register (or have run out of file).
          //perform your logic, then remove the front character
          register.Remove(0,1);
    
          //repeat the loop. You won't get any more new characters once you reach the end of file,
          //but the main loop will keep running until you set ended to true
          if(WereDone())
             ended=true;
       }
       stream.Close();
    }
    

    You could also read the entire file into a string variable, then apply a Regex that will find number characters, concatenate those into a large buffer, then fill your Register from that. That is a better approach for a small file, but this one will work for any file size.

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

Sidebar

Related Questions

I'm attempting to take values from a XML file and put them into a
I'm attempting to take 4-5 fields from a large django form and display them
I'm attempting to take large (huge) images (from a digital camera), and convert them
I'm attempting to take a string value from a Combo box then pass it
I'm attempting to take an NSImage and convert it to a string which I
I attempting to take a response from a REST service that queries an instance
I am attempting to take a value from an attribute and use it in
Im attempting to take a string that is in a partial comma separated setup.
I am attempting to take in a text file with stock market tickers taken
I am attempting to take the Name and ID fields from each object, but

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.