有人知道在这些字节中获取实际文本的正确方法是什么吗?我在这里做错了。
还有一个问题:utf-8 是最通用的编码,可以正确显示大部分字符吗?
泰
private void device_OnPacketArrival(object sender, SharpPcap.CaptureEventArgs e)
{
string str = string.Empty;
var time = e.Packet.Timeval.Date;
var len = e.Packet.Data.Length;
str = "time.Hour: " + time.Hour + " time.Minute: " + time.Minute + " time.Second: " + time.Second + " time.Millisecond: " + time.Millisecond + "len: " + len;
str += Environment.NewLine + e.Packet.ToString();
str += Environment.NewLine + " Message: " + BitConverter.ToString(e.Packet.Data);
//str += e.Packet.Data + Environment.NewLine + Environment.NewLine;
Packet p = Packet.ParsePacket(e.Packet);
str += e.Packet.Data + Environment.NewLine + Environment.NewLine;
byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, e.Packet.Data);
str += Encoding.UTF8.GetBytes(utf8Bytes.ToString()).ToString();
//txtOutput.Text += "time.Hour: " + time.Hour + "time.Minute: " + time.Minute + "time.Second: " + time.Second + "time.Millisecond:" + time.Millisecond + "len:" + len;
//txtOutput.Text += e.Packet.ToString();
//txtOutput.Text += Environment.NewLine;
WriteToFile(str,null);
// WriteToFile("",c);