作者james732 (好人超)
看板C_Sharp
標題Re: [問題] 請問string的內容如何改成byte?
時間Thu Jan 21 12:00:43 2010
※ 引述《liaommx (Orz)》之銘言:
: 我有幾個字串,
: 字串本身就是byte編碼的內容...
: 假設我字串是FF,FF,FF,F1
: 我希望透過byte傳送{0xFF,0xFF,0xFF,0xF1}
: 這樣,我應該怎麼解決編碼問題呢?
: 用convert.tobyte都只會把它當作"字串"轉成byte....
: 這不是我要的...
static void Main(string[] args)
{
string str = "FF,FF,FF,F1";
string[] str2 = str.Split(',');
for (int i = 0; i < str2.Length; i++)
{
byte b = byte.Parse(str2[i],
System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(b);
}
}
參考資料:
http://msdn.microsoft.com/zh-tw/library/bb311038.aspx
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.171.46
推 liaommx:感謝,我研究一下 01/21 12:14
推 liaommx:搞定了..:P...我回文一下.. 01/21 12:28
推 takashi737: locationDec = (int)locationTxt.Text[0]; 01/25 17:27
→ takashi737:location = Convert.ToString(locationDec, 16); 01/25 17:27