简体   繁体   中英

C# convert bytes of serialized object to string

I have a problem at the moment that I don't know how to solve.

The technical progress is sending bytes from a TCPClient to a TCPServer. The sent message is as example: 1-[BYTES-OF-SERIALIZED-OBJECT] Now I have to convert these bytes (from a byte array) to a string to work with regex.

Does anyone have an idea to solve this? Because when I convert the byte array to a string no encoding works to decode. Maybe I have to convert the serialized bytes in the square brackets to something different and then convert it back? Any idea?

The solution was to serialize the objects to a base64 encode string. The sent message is now as example: (1)[BASE64STRING-OF-SERIALIZED-OBJECT]. Now I can work with regex and don't have to format the base64 string again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM