Re: [問題] 請問string的內容如何改成byte?

看板C_Sharp作者 (好人超)時間14年前 (2010/01/21 12:00), 編輯推噓3(301)
留言4則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《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

01/21 12:14, , 1F
感謝,我研究一下
01/21 12:14, 1F

01/21 12:28, , 2F
搞定了..:P...我回文一下..
01/21 12:28, 2F

01/25 17:27, , 3F
locationDec = (int)locationTxt.Text[0];
01/25 17:27, 3F

01/25 17:27, , 4F
location = Convert.ToString(locationDec, 16);
01/25 17:27, 4F
文章代碼(AID): #1BLz5kwf (C_Sharp)
文章代碼(AID): #1BLz5kwf (C_Sharp)