none
請問字串如何拆開呢? RRS feed

  • 問題

  •     Public Overloads Sub Write(ByVal Buffer As String)
            Dim oEncoder As New System.Text.ASCIIEncoding
            Dim oEnc As Encoding = oEncoder.GetEncoding(1252)
            Const H_0 As Byte = &HC     '0x0C
            Const H_1 As Byte = &H1     '0x01
            Const H_2 As Byte = &H53    '53H = S
            Const H_3 As Byte = &H30    '30H = 0
            Const H_4 As Byte = &H31    '31H = 1
            Const H_5 As Byte = &H4B    '4BH = K
            Const H_6 As Byte = &H30    '30H = 0
            Const STX As Byte = &H2     '0x02 = STX
            Dim str_buffer() As Byte = oEnc.ASCII.GetBytes(Buffer)

            'Const V_M As Byte = (str_buffer)
            Const ETX As Byte = &H3     '0x03 = ETX
            Const BCC As Byte = &H20    '20H = 同位元檢查的最後一個位元
            Dim CHECKSUN As Byte

            Dim aByte() As Byte = oEnc.ASCII.GetBytes(Chr(12) & Chr(1) & Chr(83) & Chr(48) & Chr(49) & Chr(75) & Chr(48) & Chr(2) & Buffer & Chr(3) & Chr(102)) 'oEnc.GetBytes(Buffer)

    '請問 以上的aByte()裡Buffer會得到 "M02"

    '我如何將M02拆開後丟到分別為H_7 , H_8 , H_9的參數裡呢

    '變成H_7=&4D , H_8=&H30 , H_9=&H32
            CHECKSUN = ((((((((H_1 Xor H_2) Xor H_3) Xor H_4) Xor H_5) Xor H_6) Xor STX) Xor ETX) Or BCC)


            Me.Write(aByte)
        End Sub

     

    謝謝大大們的解惑

    2006年6月21日 上午 08:04

解答

  • 應該是

    Dim H_7 as String= Buffer.substring(0,1)

    Dim H_8 as String= Buffer.substring(1,1)

    Dim H_9 as String= Buffer.substring(2,1)

     

    2006年6月21日 上午 09:14

所有回覆