參考: http://rfid-fantasy.blogspot.com/2009/07/byte.html 字串轉bytes
using System.Text;
String name = "張京介";
Encoding.UTF8.GetBytes(name); // {229, 188, 181, 228, 186, 172, 228, 187, 139}
Encoding.Default.GetBytes(name); // {177, 105, 168, 202, 164, 182}
Encoding.Unicode.GetBytes(name); // {53, 95, 172, 78, 203, 78}
'------byte陣列轉字串--------
MsgBox(Encoding.Default.GetString(item_bytes))
以下是應用範例
'-------針對RecodrType來做 frame內部項目分離------------------------
Select Case Record_type
Case "MIR"
item_list = Class_stdf_MIR.decode_MIRtoCP(Bcontent)
Dim iss = 0
'---組合item 字串------------
'
' frame/
' frame/
' item->item_str
' item->item_str
Dim item_str(31) As String
For j = 0 To item_list.Length - 1
Dim mm = item_list(j)
Dim item_bytes = Class_stdf_MIR.get_frameBuffer(Bcontent, mm, Bcontent(mm))
Dim str As New StringBuilder(50) '假設item最大長度50
'------byte陣列轉字串----------
'法1:
For Each m In item_bytes
str.Append(Convert.ToChar(m)) '轉換BYTEtoCHAR to組合每item字串
Next
'法2:MsgBox(Encoding.Default.GetString(item_bytes))
'------/byte陣列轉字串/--------
item_str(j) = str.ToString
ListBox1.Items.Add((j + 1).ToString + "_" + item_str(j).ToString)
Next
'---------填入 CP 項目表---------------
MIRtoCP.LOT_ID = item_str(0)
MIRtoCP.PART_TYP = ""
MIRtoCP.NODE_NAM = item_str(2)
MIRtoCP.TSTR_TYP = item_str(3)
MIRtoCP.JOB_NAM = item_str(4)
MIRtoCP.JOB_REV = item_str(5)
MIRtoCP.SUB_ID = item_str(6)
MIRtoCP.OPER_NAM = item_str(7)
MIRtoCP.FAMLY_ID = item_str(12)
MIRtoCP.FACIL_ID = item_str(17)
MIRtoCP.FLOW_ID = "CP1"
'--------/填入 CP 項目表/--------------
'---/組合item 字串-/--------------
Case "WIR"
Case "MRR"
Case "SDR"
Case "WRR"
Case "WCR"
Case "HBR"
Case "SBR"
Case "PRR"
End Select
'-------/針對RecodrType來做 frame內部項目分離/------------------------
-----------------------------------------
- Jul 12 Tue 2011 19:19
vb2010~字串和bytes互轉
close
全站熱搜
留言列表
禁止留言