VB Streamwriter set to ISO-8859-1 but file get UTF8-Without Bom encoding

Rownie

I have a problem i set the streawriter to write ISO-8853-1 but the file gets utf8 encoding. See code below:

when declaring str i set it to iso-8853-1 and when i check the output files encoding i get UTF8-without bom.

Imports System.Text
Imports System.IO

Module Module1

Sub Main()
    Using str = New StreamWriter("C:\blabla.txt", False, encoding.GetEncoding("ISO-8859-1"))
        str.Write("23124124AÖ")
        Dim encoding = str.Encoding
        str.Close()
    End Using

    Dim currentEncoding = GetFileEncoding("C:\blabla.txt")
End Sub
    Public Function GetFileEncoding(filePath As String) As Encoding
        Using sr As StreamReader = New StreamReader(filePath, True)
            sr.Read()
            Return sr.CurrentEncoding
        End Using
    End Function
End Module
Damien_The_Unbeliever

There's a reason that you have to pass encodings to the constructors of both readers and writers. Files, in and of themselves, don't have encodings. They're just a collection of bytes.

It's up to you, be selecting an encoding, to say what interpretation you want to place on those bytes. You opened the StreamReader without specifying an encoding and so it defaults to UTF-8.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Character Encoding Issue - UTF8 / iso-8859-1

From Java

Set Encoding of File to UTF8 With BOM in Sublime Text 3

From Dev

Visual Studio displaying UTF-8 (without BOM) as ISO 8859-1 (characters all messed up)

From Dev

Convert character set from ISO8859_1 to UTF8

From Dev

Decode the utf8 to ISO-8859-1 mail subject to text in .procmailrc file

From Dev

Converting UTF8 to ANSI (ISO-8859-1) in Delphi

From Dev

How to set the substitution character for encoding into ISO-8859-1

From Dev

Convert ISO-8859-7 to utf-8 without bom from linux terminal

From Dev

How to convert the encoding of a file to ISO-8859-1 in Notepad++?

From Dev

Converting from UTF8 to ISO 8859-5, getting ISO 8859-1 instead

From Dev

Create new file in WinSCP with UTF-8 without BOM encoding

From Dev

Excel save behaviour of CSV file with UTF8 encoding vs UTF8-Bom encoding

From Dev

Keep character representation when converting characters from ISO-8859-1 to UTF-8 encoding in Javascript

From Dev

Ruby converting string encoding from ISO-8859-1 to UTF-8 not working

From Dev

Encoding conversion in PHP (ISO-8859-1, UTF-8, CP1250)

From Dev

Apache's default encoding is ISO-8859-1 but websites are UTF-8?

From Dev

Webmin help page encoding : iso-8859-1 vs utf-8

From Dev

Ruby converting string encoding from ISO-8859-1 to UTF-8 not working

From Dev

Reading a file with ISO-8859 encoding

From Dev

Send request with ISO-8859-1 encoding

From Dev

Encoding characters with ISO 8859-1 in Python

From Dev

encoding NSURL in ISO-8859-1

From Dev

Send request with ISO-8859-1 encoding

From Dev

encoding NSURL in ISO-8859-1

From Dev

NLS_CHARACTERSET WE8ISO8859P1 and UTF8 issues in Oracle

From Dev

changing encoding UTF8 to UTF8 BOM with rebol

From Dev

For what reason htmlspecialchar() default charset changed from ISO-8859-1 to UTF8

From Dev

Convert text value in SQL Server from UTF8 to ISO 8859-1

From Dev

jQuery or Javascript: Convert from ISO-8859-1 to utf8

Related Related

  1. 1

    Character Encoding Issue - UTF8 / iso-8859-1

  2. 2

    Set Encoding of File to UTF8 With BOM in Sublime Text 3

  3. 3

    Visual Studio displaying UTF-8 (without BOM) as ISO 8859-1 (characters all messed up)

  4. 4

    Convert character set from ISO8859_1 to UTF8

  5. 5

    Decode the utf8 to ISO-8859-1 mail subject to text in .procmailrc file

  6. 6

    Converting UTF8 to ANSI (ISO-8859-1) in Delphi

  7. 7

    How to set the substitution character for encoding into ISO-8859-1

  8. 8

    Convert ISO-8859-7 to utf-8 without bom from linux terminal

  9. 9

    How to convert the encoding of a file to ISO-8859-1 in Notepad++?

  10. 10

    Converting from UTF8 to ISO 8859-5, getting ISO 8859-1 instead

  11. 11

    Create new file in WinSCP with UTF-8 without BOM encoding

  12. 12

    Excel save behaviour of CSV file with UTF8 encoding vs UTF8-Bom encoding

  13. 13

    Keep character representation when converting characters from ISO-8859-1 to UTF-8 encoding in Javascript

  14. 14

    Ruby converting string encoding from ISO-8859-1 to UTF-8 not working

  15. 15

    Encoding conversion in PHP (ISO-8859-1, UTF-8, CP1250)

  16. 16

    Apache's default encoding is ISO-8859-1 but websites are UTF-8?

  17. 17

    Webmin help page encoding : iso-8859-1 vs utf-8

  18. 18

    Ruby converting string encoding from ISO-8859-1 to UTF-8 not working

  19. 19

    Reading a file with ISO-8859 encoding

  20. 20

    Send request with ISO-8859-1 encoding

  21. 21

    Encoding characters with ISO 8859-1 in Python

  22. 22

    encoding NSURL in ISO-8859-1

  23. 23

    Send request with ISO-8859-1 encoding

  24. 24

    encoding NSURL in ISO-8859-1

  25. 25

    NLS_CHARACTERSET WE8ISO8859P1 and UTF8 issues in Oracle

  26. 26

    changing encoding UTF8 to UTF8 BOM with rebol

  27. 27

    For what reason htmlspecialchar() default charset changed from ISO-8859-1 to UTF8

  28. 28

    Convert text value in SQL Server from UTF8 to ISO 8859-1

  29. 29

    jQuery or Javascript: Convert from ISO-8859-1 to utf8

HotTag

Archive