Domanda

hi I have some text boxes which user enters information such as first name,last name ,... . I need to convert text boxes' text to hex and then convert the hex to bytes and send to device via rs232.

I know the sending via rs232 part and I also know how to convert text to bytes.

My problem is ,now, I should work with Persian characters in text boxes .It means the text for name in text box would for example like this "حسین".

How can I solve my problem?

È stato utile?

Soluzione

If i understand correctly you can try something like that

  byte[] yourStrBytes = Encoding.GetEncoding("your encoding").GetBytes("your str");
  string hexStr = BitConverter.ToString(yourStrBytes).Replace("-", "");
  byte[] hexStrBytes=Encoding.UTF8.GetBytes(hexStr);

Altri suggerimenti

As I know if you want to convert a Persian or Arabic text to it's continuse unicode in order to send them to other devices via a serial port like This question you can use following code to reach HEX values of a Persian or Arabic letter.

 private string ConvertToUTF(string input_text)
    {
        string _out = String.Empty;
        char[] _chars = input_text.ToCharArray();
        foreach (char c in _chars)
        {
            _out += ((Int16)c).ToString("X4");
        }
        return _out;
    }

Useage:

Console.WriteLine(ConvertToUTF("سلام"));
Console.WriteLine(ConvertToUTF("مرحبا"));

Provide this out put

0633064406270645
06450631062D06280627

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top