MS Response: "By Design"
Description: Opened by Mike Ober on 2005-08-16 at 06:44:43
Execute the following code:
Module Module1
Sub Main()
Dim X As String = ""
Dim I As Integer
For I = 1 To 3000
Dim c As String = ""
Dim h As Integer
For h = 1 To 80
c &= "X"
Next
X &= c & vbCrLf
Next
Debug.Print(Left$(X, 1))
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectorie
s.Desktop & "\Test.txt", X, False)
End Sub
End Module
The debug.print(Left$(X,1)) returns the expected "X". However, the first
three characters output to test.txt are "0xEF 0xBB 0xBF".
Version from the about box:
Microsoft Visual Studio 2005
Version 8.0.50215.44 (beta2.050215-4400)
Edited by Microsoft on 2005-08-18 at 10:06:23
Thank you for submitting this issue. I'm passing it to the feature team to
take a look.
-Shamez
Resolved as By Design by Microsoft on 2005-08-18 at 13:10:13
Thank you very much for submitting this issue.
This behavior is by design. As noted on Visual Studio 2005 Beta
Documentation
(
http://msdn2.microsoft.com/library/27t17sxs(en-us,vs.80).aspx): "When no
encoding is specified, UTF-8 will be used.". The first 3 bytes you saw is
the Byte Order Mark (BOM) of UTF8. If you want to write the text out using
ASCII encoding, without any BOM, you can pass in System.Text.Encoding.ASCII
as the 4th parameter of WriteAllText.
Best regards,
Huy Nguyen, Visual Basic team.
Steps to Reproduce: Run the above code and view the output file in a binary
viewer. I used the VC 6++ editor from VS 6.
Actual Results: Binary view of output file's first line is
0xEF 0xBB 0xBF followed by 80 "X" characters as expected.
The rest of the file is correct.
Expected Results: 3000 lines of 80 "X" characters with a CRLF terminating
each line.
Attachments:
Workarounds:
Primary:
Duplicates:
==========
Somewhat counter intuitive for those of use used to standard ASCII, but in a
web and international language world, it is reasonable.
Mike.