Results 1 to 10 of 10

Thread: [RESOLVED] problem using delimiter

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    281

    Resolved [RESOLVED] problem using delimiter

    the below code works fine until it runs across a line that has something like this CCD-FX200E|PV01195|"Tape End" Display Remains Burning| ....... etc..
    It's messing up because of the quote that comes after the Bar
    how can i correct this without changing the original text file

    Code:
                
                Using reader As New TextFieldParser(FilePath)
                    reader.SetDelimiters("|")
    
                    'Read the file line by line.
                    Do Until reader.EndOfData
                        Dim fields = reader.ReadFields()
                                '..do something here 
                    Loop
                End Using
    Last edited by M@dH@tter; May 12th, 2013 at 11:14 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: problem using delimiter

    add this after:

    Code:
    reader.SetDelimiters("|")
    line to add:

    Code:
    reader.HasFieldsEnclosedInQuotes = True

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: problem using delimiter

    You can't. You would need to replace the "s and then restore them after the read. Much easier all round to use the standard string split in this case.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: problem using delimiter

    Quote Originally Posted by .paul. View Post
    add this after:

    Code:
    reader.SetDelimiters("|")
    line to add:

    Code:
    reader.HasFieldsEnclosedInQuotes = True

    Won't work. It doesn't have fields enclosed in quotes, it has fields which include quotes!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    281

    Re: problem using delimiter

    hmm well
    I tried .pauls suggestion added the following..
    Code:
                    reader.SetDelimiters("|")
                    reader.TextFieldType = FieldType.Delimited
                    reader.Delimiters = New String() {"|"}
                    reader.CommentTokens = New String() {""}
                    reader.HasFieldsEnclosedInQuotes = True
    and like dunfiddlin' replied It didn't work lol

    I'm ata complete loss..i opened the text file in Ultraedit and repleced PV01195|"Tape End" with PV01195|Tape End" and it processed the line fine so i def at least nailed the problem lol

    Do i need to completely redo the code above? i hate to do that cause the person who helped me with it was extremely patient with me while i was trying to wrap my head around the database thing..but i can't use it this way..well i could if i wanted to alter the text files before trying to run the loop..but ..
    any other idea's ?
    Last edited by M@dH@tter; May 12th, 2013 at 11:59 AM.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: problem using delimiter

    Just do a readline and your own split on the delimiter.

    OT - is the forum slow?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: problem using delimiter

    vb.net Code:
    1. For Each ln In IO.File.ReadLines(filepath)            
    2. Dim fields = ln.Split("|"c)
    3.         Next
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: problem using delimiter

    it's simple to change your code:

    Code:
    Dim lines() As String = IO.File.ReadAllLines(FilePath)
    
    For Each line As String In lines
        Dim fields() As String = line.Split("|"c)
        '..do something here 
    Next

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: problem using delimiter

    OT - is the forum slow?
    Not so's I've noticed. If anything it's worryingly rapid (no time to realise what a ridiculous thing you've just said and get ready on the edit button!)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    281

    Re: problem using delimiter

    thanks dunfiddlin and .paul that worked out fine..and i was able to keep the rest of the code intact..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width