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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:25:59+00:00 2026-05-16T10:25:59+00:00

all, I started out with what i thought was going to be a pretty

  • 0

all,

I started out with what i thought was going to be a pretty simple task. (convert a csv to “wiki” format) but im hitting a few snags that im having trouble working through

I have 3 main problems

1) some of the cells contain \r\n ( so when reading line by line this treats each new line as a new cell

2) some of the rows contain “,” ( i tried switching to \t delemited files but im still running into a problem escaping when its between two “”)

3) some rows are completely blank except for the delmiter (“,” or “\t”) others are incomplete (which is fine i just need to make sure that the cell goes in the correct place)

I’ve tried a few of the CSV reader classes but they would bump up agenst of teh problems listed above

I’m trying to keep this app as small as possible so i am also trying to avoid dlls and large classes that only a small portion do what i want.

so far i have two “attempts that are not working

Atempt 1 (doesn’t handel \r\n in a cell)

OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            openFileDialog1.Filter = "tab sep file (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (cb_sortable.Checked)
                {
                    header = "{| class=\"wikitable sortable\" border=\"1\" \r\n|+ Sortable table";
                }

                StringBuilder sb = new StringBuilder();
                string line;
                bool firstline = true;
                StreamReader sr = new StreamReader(openFileDialog1.FileName);

                sb.AppendLine(header);

                while ((line = sr.ReadLine()) != null)
                {

                    if (line.Replace("\t", "").Length > 1)
                    {
                        string[] hold;
                        string lead = "| ";

                        if (firstline && cb_header.Checked == true)
                        {
                            lead = "| align=\"center\" style=\"background:#f0f0f0;\"| ";
                        }

                        hold = line.Split('\t');
                        sb.AppendLine(table);
                        foreach (string row in hold)
                        {
                            sb.AppendLine(lead + row.Replace("\"", ""));
                        }


                        firstline = false;
                    }
                }
                sb.AppendLine(footer);
                Clipboard.SetText(sb.ToString());
                MessageBox.Show("Done!");
        }


        }
        string header = "{| class=\"wikitable\" border=\"1\" ";
        string footer = "|}";
        string table = "|-";

attempt 2 ( can handle \r\n but shifts cells over blank cells) (its not complete yet)

OpenFileDialog openFileDialog1 = new OpenFileDialog();

        openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        openFileDialog1.Filter = "txt file (*.txt)|*.txt|All files (*.*)|*.*";
        openFileDialog1.FilterIndex = 1;
        openFileDialog1.RestoreDirectory = true;

        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            if (cb_sortable.Checked)
            {
                header = "{| class=\"wikitable sortable\" border=\"1\" \r\n|+ Sortable table";
            }


            using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
            {


                string text = sr.ReadToEnd();
                string[] cells = text.Split('\t');
                int columnCount = 0;
                foreach (string cell in cells)
                {

                    if (cell.Contains("\r\n"))
                    {
                        break;
                    }
                    columnCount++;
                }          


            }

basically all I needs is a “split if not between \” ” but im just at a loss right now

any tips or tricks would be greatly appreciated

  • 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-16T10:26:00+00:00Added an answer on May 16, 2026 at 10:26 am

    Checkout this project instead of rolling your own CSV parser.

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

Sidebar

Related Questions

No related questions found

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.