Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. CSV parsing with regex

CSV parsing with regex

Scheduled Pinned Locked Moved Visual Basic
regexcsharpdata-structuresjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    madfiddlerchris
    wrote on last edited by
    #1

    I'm trying to parse a CSV string and examples I've found so far do not appear to work with VB.NET The regular expression I'm trying to work with is ,(?=([^"]*"[^"]*")*(?![^"]*")) So if I'm coding this in VB.NET I have to replace the double quotes with two double quotes right?.... Therefore, my code is using a simple form with two controls as follows... Dim re As Regex = New Regex(",(?=([^""]*""[^""]*"")*(?![^""]*""))", RegexOptions.Compiled) Dim myArray() As String = re.Split(TextBox1.Text) TextBox2.Clear() Dim i As Integer For i = 0 To UBound(myArray) TextBox2.Text = TextBox2.Text & myArray(i) & vbCrLf Next Now if TextBox1 is A,B,C it works as expected If any of the values have double quotes round them it all goes pear shaped. Eg. a,"substr1,substr2",3.14,"hello" comes out with 7 elements in my array a ,3.14,"hello" "substr1,substr2" 3.14,"hello" 3.14 "hello" "hello" this is doing my nut! I've been looking at reference books and still can't get it to work. Is there someone out there that's going to be my saviour?!?! cheers mf

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups