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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:37:58+00:00 2026-06-14T21:37:58+00:00

I am trying to load text into memory from different text files. They are

  • 0

I am trying to load text into memory from different text files. They are all words, and they are all grouped by the length of the word in their respective text files (e.g. words3.txt, words4.txt…)

I am using StreamReader to work with the files, and because of the syntax I am fairly certain I can iterate which file it’s working with if I do it inside of a for loop. I don’t see why I should have 12 different using statements.

String[] words3 = new String[2000];

for (int i = 0; i < 12; i++)
{
    using (StreamReader sr = new StreamReader(path + "words" + (i+3) + ".txt"))
        {
            String strTemp = sr.ReadLine();
            words3 = strTemp.Split(' '); //My current logic fails here
        }
}

I wanted to iterate through my different words arrays (words3, words4… words15) but naturally I run into an issue with the name of the array that I’m storing these in. It remains unchanged and so I would simply be overwriting it 12 times. In VB.NET I could concatenate an iterator variable to the array name like so (or something closely resembling this):

words & (i+3) = strTemp.Split(' ');

This obviously won’t work in C# the way I’ve described it. What is the best approach to solving this problem? Can I put the arrays into a larger array and iterate through them somehow? In the text files the words are not stored on individual lines, they are separated by a single space. To save time, when I go to see if a user’s word is contained in my “dictionary”, I only want to search for a match in the array that houses words with the appropriate number of letters.

  • 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-14T21:37:59+00:00Added an answer on June 14, 2026 at 9:37 pm

    Use something like a dictionary:

    Dictionary<int,string[]> word_dict = new Dictionary<int,string[]>();
    
        for (int i = 0; i < 12; i++)
        {
            using (StreamReader sr = new StreamReader(path + "words" + (i+3) + ".txt"))
                {
                    String strTemp = sr.ReadLine();
                    string[] words = strTemp.Split(' ');
    
                    word_dict.Add(i + 3,words);
                }
        }
    

    Then to get the words back:

    string[] words3 = word_dict[3];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load text of all divs that have a particular class into
I'm trying to load lines of a text file containing dictionary words into an
I am trying to load some data from a text file into a vector
I am trying to load text data into a postgresql database via COPY FROM
Hei guys, I'm trying to load a long text from a .rtf file and
I'm trying to load a list of filenames from a text file and then
Trying to load a small .txt file into mysql but get all my data
I'm trying to load a large text file into MATLAB. The file has the
I have a webview and am trying to load simple UTF-8 text into it.
I'm trying to load some XML into flash to populate some dynamic text fields.

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.