J
Jim
I'm parsing a file and writing a text file with cr/lf's on the end of
line. It works fine EXCEPT I get a hex FF FE as the first two
characters of the file.
1)How do I get rid of them
2)How did they get there
3)What did I do wrong?
Jim
Here's the code:
===============================
dim counter as string = ""
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters("~")
counter = "0000*"
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String = ""
For Each currentField In currentRow
If VB.Left(currentField, 2) = "ST" Then
counter = VB.Right(currentField, 4) & "*"
End If
If VB.Left(currentField, 2) = "SE" Then
counter = "0000*"
End If
currentField = counter & currentField & vbCrLf
My.Computer.FileSystem.WriteAllText("C:/testfile.txt",
currentField, True)
Next
Catch ex As VB.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
line. It works fine EXCEPT I get a hex FF FE as the first two
characters of the file.
1)How do I get rid of them
2)How did they get there
3)What did I do wrong?
Jim
Here's the code:
===============================
dim counter as string = ""
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters("~")
counter = "0000*"
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String = ""
For Each currentField In currentRow
If VB.Left(currentField, 2) = "ST" Then
counter = VB.Right(currentField, 4) & "*"
End If
If VB.Left(currentField, 2) = "SE" Then
counter = "0000*"
End If
currentField = counter & currentField & vbCrLf
My.Computer.FileSystem.WriteAllText("C:/testfile.txt",
currentField, True)
Next
Catch ex As VB.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using