1

I'm unit testing a .NET Core solution in Visual Studio 2022 on Windows.

In my solution I want to output an ANSI string stored in a byte buffer, but that doesn't seem to work.

This is an extract of the byte buffer:

byte[] test = new byte[] {65, 32, 150, 32, 66};

The text to extract is: A – B.

This is what I tried so far:

Encoding.ASCII.GetString(buffer);

A ? B


Encoding.Latin1.GetString(buffer);

A \u0096 B


Encoding.UTF8.GetString(buffer);

A � B


Encoding.UTF8.GetString(buffer);


Encoding.GetEncoding(1252).GetString(buffer)
'Encoding.GetEncoding(1252).GetString(buffer)' raised an exception of type'System.NotSupportedException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233067
    HelpLink: null
    InnerException: null
    Message: "No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method."
    Source: "System.Private.CoreLib"
    StackTrace: "   bei System.Text.Encoding.GetEncoding(Int32 codepage)"
    TargetSite: {System.Text.Encoding GetEncoding(Int32)}

Only the following code pages are available while I'm running the Visual Studio 2022 debugger:

Encoding.GetEncodings().Length

7
Code Page Name
1200 utf-16
1201 utf-16BE
12000 utf-32
12001 utf-32BE
20127 us-ascii
28591 iso-8859-1
65001 utf-8

How can I correctly decode the above text?


AxD
  • 2,714
  • 3
  • 31
  • 53

0 Answers0