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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:36:47+00:00 2026-05-16T02:36:47+00:00

I have a text file that contains a data like ID Name Path IsTrue

  • 0

I have a text file that contains a data like

ID        Name          Path                                    IsTrue        Period
1         "1 yr"        "C:\\Program Files\\My File.xyz"        -1            2"
1         "1 yr"        "C:\\Program Files\\My File.xyz"        -1            2"

now I have the following code to split the line

string[] ArrSeperators = { " " };
ArrSplitStrs = CurrStr.Split(ArrSeperators,
                             StringSplitOptions.RemoveEmptyEntries);

CurrStr represents each line of text file.

The problem is it split the name and path into multiple string but they must be treated as a single string. I cannot make any changes to file as it is a standard file across different products.

I am not getting what I can do.

  • 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-16T02:36:48+00:00Added an answer on May 16, 2026 at 2:36 am

    Use an algorithm like this:

    Process each character of each line one at a time.

    Count every ” that you find.

    If the number of “s is odd, you know that you need to keep reading the current field until you hit another “.

    If the number of “s is even, you know that as soon as you hit a space you’re on to the next field.

    Something like (this may have errors – I’ve just written it off the top of my head):

    StringBuilder field = new StringBuilder();
    int quoteCount = 0;
    
    foreach (char c in line)
    {
        if (c == '"')
        {
            quotCount++;
            continue;
        }
    
        if (quoteCount % 2 = 0)
        {
            if (c == ' ')
            {
                yield return field.ToString();
                field.Length = 0;
            }
            else
            {
                field.Append(c);
            }
        }
        else
        {
            field.Append(c);
        }
    }
    

    EDIT:

    Here’s a hacky example that works for your sample – the GetFields method needs some refactoring and it’s far from the quality of anything I’d put in my code, but the basic principle is there.

    class Program
    {
        static void Main(string[] args)
        {
            var records = ReadFile(@"D:\x.txt");
    
            foreach (var record in records)
            {
                foreach (var field in record)
                {
                    Console.Write(field + " | ");
                }
    
                Console.WriteLine();
            }
    
            Console.ReadKey();
        }
    
        static IEnumerable<IEnumerable<String>> ReadFile(String file)
        {
            using (var reader = new StreamReader(file))
            {
                // Ignore column titles line.
                reader.ReadLine();
    
                while (!reader.EndOfStream)
                {
                    yield return GetFields(reader.ReadLine());
                }
            }
        }
    
        static IEnumerable<String> GetFields(String line)
        {
            Int32 quoteCount = 0;
            StringBuilder field = new StringBuilder();
    
            foreach (var c in line)
            {
                if (c == '"')
                {
                    quoteCount++;
                    continue;
                }
    
                if (quoteCount % 2 == 0)
                {
                    if (c == ' ')
                    {
                        if (field.Length > 0)
                        {
                            yield return field.ToString();
                            field.Length = 0;
                        }
                    }
                    else
                    {
                        field.Append(c);
                    }
                }
                else
                {
                    field.Append(c);
                }
            }
    
            yield return field.ToString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Text file that contains data separated with a comma , . How
I have a text file that contains cached data in JSON format. I'm trying
I have a text file which contains columns of data that are either integer,
Let's say I have a tab-delimited text file that contains data arranged in columns
I have a text file that contains the following data. The first line is
I have a text file that contains some strings separated by ,. Strings are
I have a text file that contains a list of filenames, minus the extension,
I have a text file that contains unix style line endings: a 0x0A at
Can anyone give me any pointers. I have a text file that contains dates
I have a simple java code that reads text csv file that contains sentences

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.