Your For Loop is starting at 0 and stepping -2 which isn't helping (the code in the loop never actually executes).
The following should help get you started:Code:For i = 0 To bArr.Length - 1 Step -2
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Using a Big Endian Unicode encoding (utf-16BE) ' as is required for the desired output format Dim enc As Encoding = System.Text.Encoding.GetEncoding("utf-16BE") ' Encode the string to a byte array Dim realStr As String = "السلام عليكم" Dim bArr As Byte() = enc.GetBytes(realStr) ' build the hex string using a StringBuilder Dim hexStrBuilder As New System.Text.StringBuilder For i = 0 To bArr.Length - 1 hexStrBuilder.Append(bArr(i).ToString("X2")) Next ' Convert the value of the StringBuilder ' to a String value for display Dim hexStr As String = hexStrBuilder.ToString ' display the results MessageBox.Show(hexStr) End Sub
The above outputs 062706440633064406270645002006390644064A06430645
from "السلام عليكم"




Reply With Quote