有一段判斷是否為big5的code
private bool IsBig5Code(string word)//判斷編碼
{
byte[] bytes = Encoding.GetEncoding("Big5").GetBytes(word.ToString());
if (bytes.Length <= 1) // if there is only one byte, it is ASCII code
{
return false;
}
else
{
byte byte1 = bytes[0];
byte byte2 = bytes[1];
if ((byte1 >= 129 && byte1 <= 254) && ((byte2 >= 64 && byte2 <=
126) || (byte2 >= 161 && byte2 <= 254))) //判断是否是Big5
{
return true;
}
else
{
return false;
}
}
}
如果現在我用
WebClient client = new WebClient();
byte[] data = client.DownloadData(xxxx);
我抓到的是bytes
我現在的作法是先 Encoding.GetEncoding(-0).GetString(data)
再用string丟進去function
但是這樣好像多此一舉
可以直接把 data 丟進這個function嗎..?
直接丟進去感覺好像怪怪的??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.225.107.129