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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:42:36+00:00 2026-06-16T05:42:36+00:00

I have a a text file that looks like tabs.main=****** tabs.settings=****** settings.setting1=****** settings.setting2=****** settings.setting3=******

  • 0

I have a a text file that looks like

tabs.main="******"
tabs.settings="******"

settings.setting1="******"
settings.setting2="******"
settings.setting3="******"
settings.setting4="******"

settings.setting5.title="******"
settings.setting5.settingoption1="******"
settings.setting5.settingoption2="******"

What I’d like to be able to do is parse this into a multi-leveled dictionary. For example, I’d have a root dictionary that looks like this Dictionary<string, object> and in that I would have tabs and settings which were both Dictionary<string, object> them selves. In a graphical form what I’d like is:

Dictionary<string, object>
   -> Dictionary<"tabs", object>
      -> Dictionary<"main", "*******">
      -> Dictionary<"settings", "*******">
   -> Dictionary<"settings", object>
      -> Dictionary<"setting1", "*******">

And so on and so forth. Is this possible? And if so, could someone give me a pointer in the right direction.

  • 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-16T05:42:37+00:00Added an answer on June 16, 2026 at 5:42 am

    The problem you are going to run into is that some of your keys are going to need to be stored in the dictionary with values (strings presumably) and some of them will need to be stored with Dictionaries.

    In your example you listed:

    settings.setting5="******"
    settings.setting5.settingoption1="******"
    

    These two lines contradict each other. settings.settings5 would have the key settings5 store a value in the dictionary, but the next line is expecting settings5 to be a dictionary of other values.

    You could write a block of code like this:

    var settings = new Dictionary<string, object>();
    var lines = File.ReadAllLines("...");
    foreach (var line in lines)
    {
        var parts = line.Split(new char[] { '=' }, 2);
        if (parts.Length != 2) continue;
    
        var keys = parts[0].Split('.');
        var value = parts[1];
    
        var dict = settings;
        for (int i = 0; i < keys.Length - 1; i++)
        {
            if (!dict.ContainsKey(keys[i]))
                dict.Add(keys[i], new Dictionary<string, object>());
            dict = (Dictionary<string, object>)dict[keys[i]];
        }
    
        dict.Add(keys[keys.Length - 1], value);
    }
    
    1. It doesn’t have any error checking.
    2. You’ll find that while it does populate your objects. It is a pain to retrieve values from it. Since you have to cast each result to either a string or another Dictionary.

    Either way you’ll find that you will most likely want to avoid trying to creating dictionaries of dictionaries for this purpose.

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

Sidebar

Related Questions

I have a text file that looks like this. A 102 B 456 C
I have a text file that looks like this: value1 value2 value3 There are
I have a text file that looks a bit like: random text random text,
I have a file (called print_1012720.txt ) that looks like the text shown below.
I have a text file that looks like this: STUFF UP HERE APEXED NUMBER
I have a text file that looks like this: Id:001;status:open;Id:002;status:open;Id:003;status:closed; Id:004;status:open;Id:005;status:closed;Id:006;status:open; .... .... Here
I have a text file that looks like this: 1,Smith, 249.24, 6/10/2010 2,Johnson, 1332.23,
I have text file looks like that: float a[10] = { 7.100000e+000 , 9.100000e+000
I have a text file that is tab delimited and looks like: 1_0 NP_045689
I have a text file that looks like this: [22/Nov/2011 12:57:58] GET /media/js/jquery-1.4.3.min.js HTTP/1.1

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.