paparazzo
paparazzo

Reputation: 45096

Convert Byte Array to Text With Byte Order Mark Detection

Trying to figure out the byte[] equivalent of this

    string getText = string.Empty;
    using (StreamReader sr = new StreamReader((System.IO.Stream)File.OpenRead(unc), true))
    {
        getText = sr.ReadToEnd();
    }

Would like to convert a byte[] to string with specified byte order mark detection option like is available with StreamReader.

Upvotes: 0

Views: 162

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500525

You can still use StreamReader - just wrap the byte array in a MemoryStream. (It's not clear why you're casting File.OpenRead to Stream, by the way...)

using (StreamReader sr = new StreamReader(new MemoryStream(data)))

Upvotes: 1

Related Questions