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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:29:02+00:00 2026-06-15T10:29:02+00:00

edit as question is unanswered I have a filtered output based on 1 criteria

  • 0

edit as question is unanswered

I have a filtered output based on 1 criteria (first 3 numbers are 110,210 or 310,to give 3 distinct groups) to console from streamreader. Question edited because first answer was a literal solution to the specific example I gave, the real strings I’m using are 450 ASCII characters long. I have adjusted the example strings to remedy this, anything that works on the sample data will work on what I have.

so what i really need is something that can, depending on the first 3 numbers, take the 3 letters from a predesignated known location (for 210’s it’ll be character slot 14-16 and then using that as a subcategory, sum up all entries in character slot 33-37, and output those).

example strings:

210!!!!123244AAA75AWEHUIHJUAS!!!11111
210???1223455ABC76554HJHSDFQ????22222
210--32455623ABCFFCDGHDSFAS-----33333
310         1232451    2ABC34       GAERsASDFASDG1234523   44444
310 1234a354GDSAASDR  3 AAA  GF234523653hfdssdgSDASDF      11111
310 12378HJK1234        ABC HJHJK123462 ASDHDFS FA REW     22222
4101111ASDJF     1ABCASF        D1234    ASGF66666
4102222QW12362ER2 ABC 23459876HJKXC          11111
41033333T123 1RWE AAA  ASDFHJKRTR  WQ        22222

At the end of this, my output would be:

210 AAA 11111
210 ABC 55555
310 ABC 66666
310 AAA 11111
410 ABC 77777
410 AAA 22222

The ABC, AAA etc. are always in the same location for the same starting number, but will be different per starting number.

Likewise the location of the amounts being summed up are also only in the same place per each starting number.

I’ve tried adding some string.split to the existing code (below) but haven’t had any luck.

// Read in a file line-by-line, and store in a List.
List<string> list = new List<string>();
using (StreamReader reader = new StreamReader("file.dat"))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        var beginning = line.Substring(0, 3);
        if (beginning != "210" && beginning != "310" && beginning != "410")
            continue;
        list.Add(line); // Add to list.
        Console.WriteLine(line); // Write to console.
    }
}
  • 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-15T10:29:03+00:00Added an answer on June 15, 2026 at 10:29 am

    (Posting this answer here, as the other question is closed.)
    Using ReadAllText will be inefficient for large files.

    public static class LinqToTextReader {
        public static IEnumerable<string> AsEnumerable(this TextReader reader) {
            string line;
            while ((line = reader.ReadLine()) != null) {
                yield return line;
            }
        }
    }
    
    class Program {
        static void Main(string[] args) {
            using (StreamReader reader = new StreamReader("file.dat")) {
                var locations = new Dictionary<string, int[]>() {
                    {"210", new [] {406, 409, 129, 140, 142, 153}},
                    {"310", new [] {322, 325, 113, 124, 126, 137}},
                    {"410", new [] {478, 481, 113, 124, 126, 137}}
                };
    
                var query =
                    from line in reader.AsEnumerable()
                    let lineStart = line.Substring(0, 3)
                    where lineStart == "210" || lineStart == "310" || lineStart == "410"
                    let currentLocations = locations[lineStart]
                    select new {
                        letters = line.Substring(currentLocations[0], currentLocations[1]),
                        value =
                            int.Parse(line.Substring(currentLocations[2], currentLocations[3])) +
                            int.Parse(line.Substring(currentLocations[4], currentLocations[5]))
                    };
    
                //It should be possible to combine the two queries
                var query2 = 
                    from item in query
                    group item by item.letters into letterGroup
                    select new {
                        letters = letterGroup.Key,
                        total = letterGroup.Sum(item => item.value)
                    };
    
                foreach (var item in query2) {
                    Console.WriteLine(item.letters);
                    Console.WriteLine(item.total);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit (updated question) I have a simple C program: // it is not important
(EDIT: Question changed.) I have a product with an installer which was built by
This is a followup question to my question , that was left unanswered EDIT
EDIT : This question doesn't really make sense once you have picked up what
EDIT:Question Updated. Thanks Slott. I have a TCP Server in Python. It is a
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and
EDIT: This question was initially too general, I think. So What I really need

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.