[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
Re: problem using delimiter
add this after:
Code:
reader.SetDelimiters("|")
line to add:
Code:
reader.HasFieldsEnclosedInQuotes = True
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.
Re: problem using delimiter
Quote:
Originally Posted by
.paul.
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!
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 ?
Re: problem using delimiter
Just do a readline and your own split on the delimiter.
OT - is the forum slow?
Re: problem using delimiter
vb.net Code:
For Each ln In IO.File.ReadLines(filepath)
Dim fields = ln.Split("|"c)
Next
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
Re: problem using delimiter
Quote:
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!)
Re: problem using delimiter
thanks dunfiddlin and .paul that worked out fine..and i was able to keep the rest of the code intact..