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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:54:25+00:00 2026-05-18T23:54:25+00:00

Alright, so I have a text file with some data in it, in this

  • 0

Alright, so I have a text file with some data in it, in this format:

Info1-Info2
Info3-Info4
Info5-Info6

With my program, I would like to be able to get the contents of a line, based on the first piece of information I give. So, if I give “Info3”, I would like to be able to get the value “Info4” and place it into a string.

I have the text from the text file stored in a string already, so I just need to manipulate the string so that I can get the information that I want.

Sorry if I explained this in a bad way. 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-18T23:54:25+00:00Added an answer on May 18, 2026 at 11:54 pm

    I’d use an IDictionary instead.

    When reading from your file put the left part (before “-“) as the Dictionary Key and the right part as the Value.

    Then you can just get the value by the key:

    dictionary[“Info3”] will return “Info4”.

    Let me know if you need some actual code…

    EDIT: Adding code

    namespace ConsoleApplication2 {
        class Program {
            static void Main(string[] args) {
                string line;
                //initialize Dictionary
    
                var keyMatch = new Dictionary<string, string>();
                //opening the file
                using (TextReader re = File.OpenText("Sample.txt")) {
                    //loop through lines
                    while ((line = re.ReadLine()) != null) {
                        keyMatch.Add(line.Substring(0, line.IndexOf("-")), line.Substring(line.IndexOf("-") + 1));
                    }
                }
    
                var test = keyMatch["Info5"];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright so I have this C++ image capturing class. I was wondering if I
Alright, currently I have my SWF hitting a php file that will go and
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
I have a text file with a list of macro names (one per line).
I have been trying to load a text file into a combobox, and then
Alright, I have library I wrote in C that reads a file and provides
Alright I want to create a .csv file in C#. I have been looking
alright so I am trying to read a text file. and then split it

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.