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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:17:05+00:00 2026-06-18T16:17:05+00:00

I have a text file that has the following in it: (Without quotation marks

  • 0

I have a text file that has the following in it: (Without quotation marks and “Empty Space”)

  • ##############
  • # Empty Space#
  • # Empty Space#
  • # Empty Space#
  • # Empty Space#
  • ##############

I want to add this whole file row by row into a list:

FileStream FS = new FileStream(@"FilePath",FileMode.Open);
StreamReader SR = new StreamReader(FS);
List<string> MapLine = new List<string>();

foreach (var s in SR.ReadLine())
{
    MapLine.Add(s.ToString());                   
}

foreach (var x in MapLine)
{
    Console.Write(x);
}

Here comes my problem: I want to add this into a Two dimensional array. I tried:

string[,] TwoDimentionalArray = new string[100, 100];

for (int i = 0; i < MapLine.Count; i++)
{
    for (int j = 0; j < MapLine.Count; j++)
    {
        TwoDimentionalArray[j, i] = MapLine[j].Split('\n').ToString();
    }
}

I am still new to C# so please any help will be appreciated.

  • 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-18T16:17:07+00:00Added an answer on June 18, 2026 at 4:17 pm

    You can try with this:

            // File.ReadAllLines method serves exactly the purpose you need
            List<string> lines = File.ReadAllLines(@"Data.txt").ToList();
    
            // lines.Max(line => line.Length) is used to find out the length of the longest line read from the file
            string[,] twoDim = new string[lines.Count, lines.Max(line => line.Length)];
    
            for(int lineIndex = 0; lineIndex < lines.Count; lineIndex++)
                for(int charIndex = 0; charIndex < lines[lineIndex].Length; charIndex++)
                    twoDim[lineIndex,charIndex] = lines[lineIndex][charIndex].ToString();
    
            for (int lineIndex = 0; lineIndex < lines.Count; lineIndex++)
            {
                for (int charIndex = 0; charIndex < lines[lineIndex].Length; charIndex++)
                    Console.Write(twoDim[lineIndex, charIndex]);
    
                Console.WriteLine();
            }
    
            Console.ReadKey();
    

    This is going to save each character of the file content into it’s own position in a 2-dimensional array. For that purpose char[,] might have also been used.

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

Sidebar

Related Questions

I currently have a text file that has the following: 1 Commercial & Enterprise
I have a text file that I want to edit using Java. It has
I have a xml file <text> <defalut>This file has the following features:</defalut> <value> <ul>
I have a text file that has the following layout: text text .. CUT
I have a text file that has following content: ac und accipio annehmen ad
I have a large text file that has the following headings that I'm trying
I have text file that has the following strings: coordsys = Z:/SatData/Satimages/Project/Mtsat/mtsat-2r/nrl/NW-Pacific/Geo-Color/Project/201108170432_DAY1.jp2 coordsys =
I have a text file that has item numbers in it (one per line).
i have a java ee project which has a text file that uses a
So I have a multipart form that has fields for text, integers and file

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.