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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:36:45+00:00 2026-05-21T21:36:45+00:00

I have a flat text file that contains the following data; Following are the

  • 0

I have a flat text file that contains the following data;

Following are the names and ages in a text file.
26|Rachel
29|Chris
26|Nathan

The data is kept on a server (e.g http://domain.com/info.dat), I’d like to read this text file and insert it into an array (age and name). I’d like to ignore the first line (Following are….).

I’ve sorted the code to grab the data file using a webclient and the code to open the dat file using streamreader as follows;

using (StreamReader sr = new StreamReader(path))
                {
                    while (sr.Peek() >= 0)
                    {
                        string[] channels = Text.Split('|');

                        foreach (string s in channels)
                        {  

                        }
                    }
                }

The problem with the above code is when it comes to inputting it into an array with the correct columns. Could anyone give me some pointers?

Many thanks

  • 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-21T21:36:46+00:00Added an answer on May 21, 2026 at 9:36 pm

    How about an answer that uses some LINQ:

    var results = from str in File.ReadAllLines(path).Skip(1)
                  where !String.IsNullOrEmpty(str)
                  let data = str.Split('|')
                  where data.Length == 2
                  select new Person { Age = Int32.Parse(data[0], NumberStyles.Integer, CultureInfo.CurrentCulture), Name = data[1] };
    

    results is now IEnumerable<Person> which you can do ToList or ToArray on to get a List<Person> or Person[], or you can simply use the results with a foreach loop.

    UPDATE: here is the Person class needed to make this more functional.

    public class Person
    {
       public int Age { get; set; }
       public string Name { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows mobile 5.0 application (smartphone) that contains a flat data file
Lets say, I have a flat text file in a server. I need to
I have simple SSIS package which reads data from flat file and insert into
I have an OLE DB Data source and a Flat File Destination in the
I have simple SSIS package where I import data from flat file into SQL
I have a tab delimited file on a shared path. I've setup that flat
I have a txt file that I’m trying to import as flat file into
I have a series of large, flat text files that I need to parse
I have a VB.Net program that reads in a flat file, and then parses
I have a fixed width text file, which has been unpacked from Comp-3 data

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.