0

Reading a Byte buffer:

while (...)
{
    builder.Append(Encoding.ASCII.GetString(buffer, index, 1));
    ++index;
}

I'm getting the following result: "20202020202020202020202057363253304b4358", which looks like ASCII or HTML character codes. What is the best and faster way to obtain the real string out of that value in C#?

2
  • 5
    How did you obtain the values in buffer to start with? A short but complete example would be really helpful here. (Additionally, you shouldn't need to append a single character at a time...) Commented May 7, 2013 at 16:59
  • The buffer is a result of a DeviceIoControl call, that's why I didn't provide any example, code was veeeery long and quite pointless. Looks like the string is somehow flipped and encoded though. Commented May 7, 2013 at 17:10

2 Answers 2

3

Although I think there is something wrong in your code while getting that string, anyway, you can use

byte[] buf = SoapHexBinary.Parse("20202020202020202020202057363253304b4358").Value;
var str = Encoding.ASCII.GetString(buf);

which would return            W62S0KCX

PS: SoapHexBinary is in wellknown System.Runtime.Remoting.Metadata.W3cXsd2001 namespace :)

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

Comments

1

If you have the entire buffer available already, then simply try:

var myString = Encoding.Default.GetString(byteBuffer);

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.