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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:20:09+00:00 2026-05-14T18:20:09+00:00

I have this code to read a CVS file. It reads each line, devides

  • 0

I have this code to read a CVS file. It reads each line, devides each line by delimiter ‘,’ and stored the field values in array ‘strline()’ .

How do I extract only required fields from the CSV file?

For example if I have a CSV File like

Type,Group,No,Sequence No,Row No,Date (newline)
0,Admin,3,345678,1,26052010 (newline)
1,Staff,5,78654,3,26052010

I Need only the value of columns Group,Sequence No and date.

Thanks in advance for any ideas.

Dim myStream As StreamReader = Nothing
    ' Hold the Parsed Data
    Dim strlines() As String
    Dim strline() As String
    Try
      myStream = File.OpenText(OpenFile.FileName)
      If (myStream IsNot Nothing) Then
        ' Hold the amount of lines already read in a 'counter-variable' 
        Dim placeholder As Integer = 0
        strlines = myStream.ReadToEnd().Split(Environment.NewLine)
        Do While strlines.Length <> -1 ' Is -1 when no data exists on the next line of the CSV file
          strline = strlines(placeholder).Split(",")
          placeholder += 1
        Loop
      End If
    Catch ex As Exception
      LogErrorException(ex)

    Finally

      If (myStream IsNot Nothing) Then
        myStream.Close()
      End If
    End Try
  • 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-14T18:20:10+00:00Added an answer on May 14, 2026 at 6:20 pm

    1) DO NOT USE String.Split!!

    CSV data can contain comma’s, e.g.

    id,name
    1,foo
    2,"hans, bar"
    

    Also as above you would need to handle quoted fields etc… See CSV Info for more details.

    2) Check out TextFieldParser – it hadles all this sort of thing.

    It will handle the myriad of different escapes you can’t do with string.split…

    Sample from: http://msdn.microsoft.com/en-us/library/cakac7e6.aspx

    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\TestFolder\test.txt")
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(",")
        Dim currentRow As String()
        While Not MyReader.EndOfData
            Try
                currentRow = MyReader.ReadFields()
                Dim currentField As String
                For Each currentField In currentRow
                MsgBox(currentField)
                Next
            Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
            End Try
        End While
    End Using
    

    The MyReader.ReadFields() part will get you an array of strings, from there you’ll need to use the index etc…

    PK 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 408k
  • Answers 409k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can check if the Bluetooth radio is on or… May 15, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer I don't think the method you suggest is possible because:… May 15, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer You can define the array inside the namespace: // this… May 15, 2026 at 6:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.