Encoding Question
From: C# Learner (csharp_at_learner.here)
Date: 02/25/04
- Next message: Michael A. Covington: "Re: Dose microsoft offer free weatherforcart services or Free for test"
- Previous message: ya1000: "Types problem?"
- Next in thread: Jon Skeet [C# MVP]: "Re: Encoding Question"
- Reply: Jon Skeet [C# MVP]: "Re: Encoding Question"
- Reply: Ray: "Re: Encoding Question"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 25 Feb 2004 16:08:49 +0000
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[i]);
}
return sb.ToString();
}
I know this is a hack, but is there a better way?
- Next message: Michael A. Covington: "Re: Dose microsoft offer free weatherforcart services or Free for test"
- Previous message: ya1000: "Types problem?"
- Next in thread: Jon Skeet [C# MVP]: "Re: Encoding Question"
- Reply: Jon Skeet [C# MVP]: "Re: Encoding Question"
- Reply: Ray: "Re: Encoding Question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|