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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:48:56+00:00 2026-06-09T03:48:56+00:00

I am using the below code to read data from a text file row

  • 0

I am using the below code to read data from a text file row by row. I would like to assign each row into an array. I must be able to find the number or rows/arrays and the number of elements on each one of them.

I would also like to do some manipulations on some or all rows and return their values.

I get the number of rows, but is there a way to to loop something like:

    *for ( i=1 to number of rows)
    do
    mean[i]<-row[i]
    done
    return mean*


var data = System.IO.File.ReadAllText("Data.txt");

var arrays = new List<float[]>();

var lines = data.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);

foreach (var line in lines)
{
    var lineArray = new List<float>();

    foreach (var s in line.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries))
    {
        lineArray.Add(Convert.ToSingle(s));
    }
    arrays.Add(lineArray.ToArray());

}

var numberOfRows = lines.Count();
var numberOfValues = arrays.Sum(s => s.Length);
  • 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-09T03:48:58+00:00Added an answer on June 9, 2026 at 3:48 am

    Found an efficient way to do this. Thanks for your input everybody!

    private void ReadFile()
        {
            var lines = File.ReadLines("Data.csv");
            var numbers = new List<List<double>>();
            var separators = new[] { ',', ' ' };
            /*System.Threading.Tasks.*/
            Parallel.ForEach(lines, line =>
            {
                var list = new List<double>();
                foreach (var s in line.Split(separators, StringSplitOptions.RemoveEmptyEntries))
                {
                    double i;
    
                    if (double.TryParse(s, out i))
                    {
                        list.Add(i);
                    }
                }
    
                lock (numbers)
                {
                    numbers.Add(list);
                }
            });
    
            var rowTotal = new double[numbers.Count];
            var rowMean = new double[numbers.Count];
            var totalInRow = new int[numbers.Count()];
    
            for (var row = 0; row < numbers.Count; row++)
            {
                var values = numbers[row].ToArray();
    
                rowTotal[row] = values.Sum();
                rowMean[row] = rowTotal[row] / values.Length;
                totalInRow[row] += values.Length;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to read data from a text file and loading it into a
I am using the below code to read .docx file and it is successfully
Working on a problem where I have to read data from a file into
In the below code, using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _emailTemplate.EmailContent
I was trying to read a lot of numbers dynamically using the code below
I am using below code to generate photo gallery from a folder. How can
i am using below code to change the the font type of text view.
I have tried using a example file using PHPExcel script to extract data from
I am using ASP.NET to read the data in the excel file. I am
I have the following code that uses Sequence objects to read data from a

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.