This is a relatively simple file writing function that takes a string() and writes each line out to a file.
The strings, built within code is something similar to this:
"01-28-2010,12:11:38,N 38°51'41.0616",W 94°49'38.9712",0.5mph,253.2°,983ft"
Everything works great, with the exception of the writing portion. It outputs the data as:
"01-28-2010,12:11:38,N 38°51'41.0616",W 94°49'38.9712",0.5mph,253.2°,983ft"
As you can see there are added characters in the string.
Public Shared Function WriteToFile(ByVal FileName As String, ByVal lines() As String) As Boolean
Try
Dim sw As New System.IO.StreamWriter(FileName)
Dim X As Integer = 1
Do While X <= UBound(lines)
sw.Write(lines(X))
X += 1
Loop
sw.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
I have checked to see if perhaps I was not creating the string properly, and each time I received similar results. I have tried these various permutations in the event there was something amis in the string building:
MyString = MyString & Chr(176)
MyString = MyString & "°"
MyString = MyString & Chr(Asc("°"))
Finally I resorted to writing the lines as binary and got similar results, but with the added problem that every character is now prepended with hex 01.
I suppose I could run the entire string through a single character byte and write that single byte out to the file, but that is so inefficient.
I have also used every encoding option available and still no dice
Also, when viewing the file with notepad, the error isn't evident, it is only when processing the file contents with another program that I became aware of the issue.
If you view the files in VIM or with a binary viewer, you can see the additional characters.