C
C# Learner
Imagine the following scenario.
You receive a byte array from a socket. This byte array contains both
text and binary data; it contains text fields delimited by specified
byte sequences.
For example:
"one \xC0\x80 two \xC0\x80 three"
The way I'm currently dealing with this is to convert the byte array to
a string with the following function, then splitting the string by the
delimiter sub-string.
public static string GetString(byte[] data)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.Length; ++i) {
sb.Append((char)data);
}
return sb.ToString();
}
I know this is a hack, but is there a better way?
You receive a byte array from a socket. This byte array contains both
text and binary data; it contains text fields delimited by specified
byte sequences.
For example:
"one \xC0\x80 two \xC0\x80 three"
The way I'm currently dealing with this is to convert the byte array to
a string with the following function, then splitting the string by the
delimiter sub-string.
public static string GetString(byte[] data)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.Length; ++i) {
sb.Append((char)data);
}
return sb.ToString();
}
I know this is a hack, but is there a better way?