I'm trying to port a class library that is reading files from a standard class library to a portable class library (.NET Standard,Version=v1.6), supporting ASP.NET Core.
I need convert a portion of a byte array to a string.
With .NET Framework 4.5 I could detect current code page with
public string ConvertToString(byte[] data, int count)
{
int CurrentCodePage = Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage;
return Encoding.GetEncoding(CurrentCodePage).GetString(data, 0, count);
}
A tool Analyze Assembly Portability gave me an advice: "Use System.Globalization.CultureInfo.CurrentCulture
."
But there is no information about current code page.
How can I convert byte[] to string in current enconding?
Edit: I'm porting a zip-compression library. And in my case I need convert byte[] to string properly. In other q&a (like How convert byte array to string) i saw using Encoding. I realized that it was the wrong approach. How can I make convert on right way?