|
-
May 12th, 2013, 10:57 AM
#1
Thread Starter
Hyperactive Member
[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.
-
May 12th, 2013, 11:37 AM
#2
Re: problem using delimiter
add this after:
Code:
reader.SetDelimiters("|")
line to add:
Code:
reader.HasFieldsEnclosedInQuotes = True
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2013, 11:39 AM
#3
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!
-
May 12th, 2013, 11:40 AM
#4
Re: problem using delimiter
 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!
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!
-
May 12th, 2013, 11:55 AM
#5
Thread Starter
Hyperactive Member
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.
-
May 12th, 2013, 12:00 PM
#6
Re: problem using delimiter
Just do a readline and your own split on the delimiter.
OT - is the forum slow?
-
May 12th, 2013, 12:02 PM
#7
Re: problem using delimiter
vb.net Code:
For Each ln In IO.File.ReadLines(filepath) Dim fields = ln.Split("|"c) 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!
-
May 12th, 2013, 12:04 PM
#8
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2013, 12:05 PM
#9
Re: problem using delimiter
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!
-
May 12th, 2013, 12:44 PM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|