2

I am trying to return a substring of a byte array.

(another application is pushing data into my database, where files have a prepended GUID attached to it. I want to remove this GUID, when giving the file back to the user)

if (bytes.Length > 38)
            {
                string s = System.Text.Encoding.ASCII.GetString(bytes);
                returnBytes = Convert.FromBase64String(s.Substring(38));
            }

Is it possible to do this without Text Encoding? Maybe via Array.Copy() ?

Thanks for any advice.

2

2 Answers 2

2

You can Use Buffer.BlockCopy

    Byte[] fileBytes = new Byte[bytes.Length - 16];
    Buffer.BlockCopy(bytes, 16, fileBytes, 0, fileBytes.Length); 

BTW Guid is normally 16 bytes length, 38 is string length

Sign up to request clarification or add additional context in comments.

1 Comment

This does work, as it truncates my byteArray, but unfortunatelly my pdf is not readable. Seems to be a problem with how many bytes to skip.
1

For the part of returning a substring of an array, you can use ArraySegment<T>. Refer to this link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.