none
How to have StreamReader read 0xDF as an "es zet"? RRS feed

  • Question

  • How to have StreamReader read 0xDF as an "es zet"? --- or have MS Word save "es zet" as 0xC3 0x178?

    When the German letter "es zet" is copied from MS Access and pasted into Notepad, the "es zet" is saved as a 0xC3 0x178.

    When the German letter "es zet" is copied from MS Word and pasted into Notepad, the "es zet" is also saved as a 0xC3 0x178.

    When MS Word is saved as a txt, the "es zet" is changed to a 0xDF.

    Notepad interprets the 0xC3 0x178 as an "es zet". Notepad also interprets the 0xDF as an "es zet".

    StreamReader(stFileName) reads a 0xC3 0x178 as an "es zet" --- it reads the 0xDF as unknown.

    (C#, WPF, Visual Studio 2019, MS Office 2019)

    bhs67

    Monday, October 21, 2019 4:15 PM

All replies

  • I am confused by your use of "saved as".
    the unicode code point of ß is U+00DF.
    That can be encoded in multiple ways, but none of them seems to result in "0xC3 0x178".
    see Unicode Character “ß” (U+00DF)
    When I test on my german system in Powershell, neither
    'ß'  | format-hex
    nor
    'ß'  | format-hex -Encoding unicode
    result in "0xC3 0x178".

    Anyway: you can specify what encoding the StreamReader should use:
    StreamReader(Stream, Encoding)
    Monday, October 21, 2019 6:31 PM
  • By saved as --- MS Word docx => File => Save As => txt.

    By copy --- Highlight the text => ctrl+C then ctrl+V.

    I uploaded "___x.txt" and "___y".txt to https://download.foxping.com/.  I'm curious if you see the same.


    bhs67

    Monday, October 21, 2019 10:11 PM
  • I opened the files in a hex editor:
    "___x.txt" is saved as UTF-8, so the ß is  "C3 9F"
    "___y.txt" is saved as ANSI, I can read it with:
    var streamReader = new StreamReader(myTeamNamesFile, Encoding.GetEncoding(1252))
    but this will of course not work when someone writes chinese characters.
    You should save in Unicode: Choose an encoding standard when you save a file



    • Edited by EckiS Wednesday, October 23, 2019 8:04 PM
    Tuesday, October 22, 2019 5:25 AM