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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:14:50+00:00 2026-06-04T02:14:50+00:00

I am working on a program that you can select a header from a

  • 0

I am working on a program that you can select a header from a csv file(it parses the headers out initially) and i want the user to be able to get the column’s data without having to read the entire file.(making a list of string arrays and pulling out the string array index for the information, which is the simple easy thing to do).

Is there a way i can use seek to do this? maybe search for a string(which would be the header) and get the information within its column.

This is the getHeader function in case it helps…

private string[] getHeader(string path)//gets the headers from the file path specified.
    {          
        List<string> row = new List<string>();

        using (StreamReader readFile = new StreamReader(path))
        {          
            row = (readFile.ReadLine().Split(',').ToList());                
        }

        return row.ToArray();

    }

(the to list and to array is there just to get around setting a size for an array initially…)

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-06-04T02:14:51+00:00Added an answer on June 4, 2026 at 2:14 am

    Impossible.

    Seek can go to a definite position in the file. This would be an OK idea if you had a fixed length record (SDF/COBOL) file with HUGE record lengths and few records.

    Unfortunately, .csv is by definition Variable Length Records. You can only tell where one record stops and starts based on hitting the cr/lf at the end of the record.

    Also this would not be a good idea even with most fixed-record formats. Due to buffering, the OS will read the whole file anyway, as you would be seeking ahead smaller amounts then the OS has preloaded.

    I can see why you would want to do this; intuitively, it sounds like it would be faster. While you should always design your code with speed in mind, this is low-level enough to qualify as ‘premature optimization’ – google that. Basically you have to prove to yourself that it runs slow by writing it, then, when you see it’s a huge impediment to functionality, you can optimize.

    Don’t parse it yourself!

    MS has an assy for that. Microsoft.VisualBasic.FileIO.TextFieldParser. Yes you can use it with C# (even though the sample below is in VB, you can figure out what you’ll need to do). Don’t be too proud to include a reference to VB. Time and money in your pocket matter, not being able to say, ‘I won’t touch anything VB with a 10-foot pole’. Changes are the assembly will already by on your target PCs. Only concern is if you have program install package download size issues, or, are deploying to a non-PC platform.

        Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(CSVPath)
    
            Reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
            Reader.Delimiters = New String() {","}
            Reader.TrimWhiteSpace = True
            Reader.HasFieldsEnclosedInQuotes = True
    
            While Not Reader.EndOfData
                Try
                    Dim st2 As New List(Of String)
                    st2.addrange(Reader.ReadFields())
                    If iCount > 0 Then ' ignore first row = field names
                        Dim p As New clsPerson
                        p.CSVLine = st2
                        While p.CSVLine.Count < 15
                            p.CSVLine.Add("")
                        End While
                        p.FirstName = st2(1).Trim
                        If st2.Count > 2 Then
                            p.MiddleName = st2(2).Trim
                        Else
                            p.MiddleName = ""
                        End If
                        p.LastNameSuffix = st2(0).Trim
                        If st2.Count >= 6 Then
                            p.TestCase = st2(5).Trim
                        End If
                        If st2(3) > "" Then
                            p.CertsFromCase.Add(st2(3))
                        End If
                        cases.Add(p)
                    Else
                        stFirstRow = CatLine(st2.ToArray)
                        Dim st3(6) As String
                        For kk As Integer = 0 To Math.Min(st2.Count - 1, 5)
                            st3(kk) = st2(kk)
                        Next
                        If 0 = InStr(st3(0), "Last Name", CompareMethod.Text) Or _
                         0 = InStr(st3(1), "First Name", CompareMethod.Text) Or _
                         0 = InStr(st3(2), "Middle Name", CompareMethod.Text) Or _
                         0 = InStr(st3(3), "Policy", CompareMethod.Text) Or _
                         0 = InStr(st3(5), "Test Case", CompareMethod.Text) Then
                            stFirstRow = "Last Name,First Name,Middle Name,Policy,,Test Case #" & vbCrLf & stFirstRow
                        End If
                    End If
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & " is not valid and will be skipped.")
                End Try
                iCount += 1
            End While
        End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that outputs a text procedure file, based on user
I am working on a program which requires a user to select the file
Im working right now on a program that can divide, add, ect, but, im
I'm working on a program that takes in a Wavefront .obj file and eventually
I'm working on a program that needs to be able to load object-properties from
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
I've got a program that I'm working on and I use select to choose
I'm writing a program in Ruby that downloads a file from an RSS feed
I am working on a program that users can log in to and see
I'm working on a program that will sort files based on extension I currently

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.