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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:10:27+00:00 2026-06-02T17:10:27+00:00

I currently have a method that reads ints from a file and upon reaching

  • 0

I currently have a method that reads ints from a file and upon reaching 16 ints a regex is run against the string (register). Although the way the ints (or numbers) are read in from the file is causing me problems. It currently reads all of the numbers from a file and disregards any other chars such as letters. Hence the following would be collected:

Example.txt:

h568fj34fj390fjkkkkf385837692g1234567891011121314fh

Incorrect output:

5683439038583769

Correct output:

1234567891011121

But I only want to collect a string of consecutive numbers (if there are other chars like letters inbetween the numbers they would not be counted) and the method would such for a series of numbers (16 in total) with no other chars like letters inbetween.

My current logic is as follows:

    var register = new StringBuilder();

    using(var stream = File.Open(readme.txt, FileMode.Open))
    {
                bool execEnd = false;
                bool fileEnded = false;

                int buffer;
                while(execEnd = true)
                {
                while(register.Length < 16 && !fileEnded)
                    {
                buffer = stream.ReadByte();
                if(buffer == -1)
                {
                fileEnded = true;
                break;
                }

     var myChar = (char)buffer;
     if(Char.IsNumber(myChar))
    register.Append(myChar);
      }
  • 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-02T17:10:28+00:00Added an answer on June 2, 2026 at 5:10 pm

    This should be your required Regex: \d{16}

    So you could use LINQ to find all matches:

    var allMatches = 
         System.IO.File.ReadLines(path)
        .Select(l => System.Text.RegularExpressions.Regex.Match(l, @"\d{16}"))
        .Where(m => m.Success)
        .ToList();
    
    foreach (var match in allMatches)
    {
        String number = match.Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a Generic method that reads an Value from the database based
I have an object that reads data from an Excel file using, which takes
i currently have a method that checks what is around the centre item in
I have a method in Java that concatenates 2 Strings. It currently works correctly,
Currently I have created a ABCFactory class that has a single method creating ABC
Hey, I currently have a Currency Format method: private string FormatCurrency(double moneyIn) { CultureInfo
I am learning TDD and I currently have a method that is working but
I have an application that reads from a COM Port and then does something
So, I have a group of ASINetworkQueues that currently run together resulting in a
I have a simple application that reads data in small strings from large text

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.