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

  • Home
  • SEARCH
  • 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 6614957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:24:10+00:00 2026-05-25T20:24:10+00:00

I need to extract data from a text file in ASP .NET. Example Data:

  • 0

I need to extract data from a text file in ASP .NET.

Example Data:

    ; comment
    data = astringvalue
    ; comment
    ; string values
    person = bob
    animal = rabbit
    ; boolean values (yes / no)
    isValid = yes
    isAnimal = no

I will be creating a GUI control for each line that is not a comment.
What is the best way to extract each line and determine if it is a string or a Boolean value.
Performance is a must as the file can be quite large.

Edit: At some point i will have need to update the values with the updated ones from the web page.

private void ShowConfig()
    {
    string configLine = String.Empty;
using (TextReader tr = File.OpenText(@"textfile"))
            {
            do
                {
                configLine = tr.ReadLine();
                if (!String.IsNullOrEmpty(configLine) && !configLine.Contains(Convert.ToChar(";")))
                    {
                    CreateControl(configLine);
                    }
                } while (configLine != null);
            }   

private void CreateControl(string configline)
    {
    string lineHeader = string.Empty;
    string lineValue = String.Empty;
    for (int i = 0; i < configline.Length; i++)
        {
        if (configline[i] == Convert.ToChar("="))
            {
            lineHeader = configline.Remove(i).TrimEnd();
            lineValue = configline.Remove(0, ++i).TrimStart();
            if (GetValueType(lineValue) is CheckBox)
                {
                this.Panel1.Controls.Add(CreateCheckBox(lineValue, lineHeader));
                }
            else
                {
                this.Panel1.Controls.Add(CreateLabel(lineHeader));
                this.Panel1.Controls.Add(CreateTextBox(lineValue, lineHeader));
                }
            this.Panel1.Controls.Add(CreateNewLine());
            break;
            }
        }
    }

private Control GetValueType(string Value)
    {
    switch (Value)
        {
        case "yes":
        case "no":
            return new CheckBox();
        default:
            return new TextBox();
        }
    }

In the future i will need to check for more value types than string and boolean.

  • 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-25T20:24:10+00:00Added an answer on May 25, 2026 at 8:24 pm

    How about something like this? However, I think that working any kind of serious type-recognition into this schema is likely to be error prone. Why not use a better serialization in the first place? Something that captures type info in the serialized data?

    var data=@" ; comment
        data = value
        ; comment
        ; string values
        person = Bob
        animal = Rabbit
        ; boolean values (yes / no)
        isValid = yes
        isAnimal = no";
    
    var parsed = data
        .Split(new[]{"\r\n","\r","\n"}, StringSplitOptions.RemoveEmptyEntries)
        .Select(line => line.Trim())
        .Where(line => !line.StartsWith(";"))
        .Select(line => line.Split('=').Select(item => item.Trim()))
        .Where(kv => kv.Count() == 2)
        .Select(kv => new{key = kv.First(), value = kv.Last()})
        .Select(kv => 
            new{kv.key, kv.value, isBool = Regex.IsMatch(kv.value,"yes|no")});
    

    Taking @Rubens’ comments on-board, if the data source is too large to load in at once, you could stream the data with the addition of a helper method:

    static IEnumerable<string> Lines(string filename)
    {
        using (var sr = new StreamReader(filename))
        {
            while (!sr.EndOfStream)
            {
                yield return sr.ReadLine();
            }
        }
    }
    

    then:

    Lines(@"c:\path\to\data")
        .Select(line => line.Trim())
        .Where(line => !line.StartsWith(";"))
        .Select(line => line.Split('=').Select(item => item.Trim()))
        .Where(kv => kv.Count() == 2)
        .Select(kv => new{key = kv.First(), value = kv.Last()})
        .Select(kv => 
            new{kv.key, kv.value, isBool = Regex.IsMatch(kv.value,"yes|no")});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract data from a .mpp file on the network and combine
I have a pgp-encrypted file that I need to extract data from at runtime.
I need to extract data from my MySQL database into multiple text files. I
I need to extract certain data from a file, but this file is formatted
I need to extract a few fields of data from many lines of text.
I need to extract the text from a PDF file. This text will likely
I need to extract data from a structure and put it into a list,
I need to extract data from a source that presents it in one of
Sometimes I need to quickly extract some arbitrary data from XML files to put
I have a string in c# containing some data i need to extract based

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.