2

How can I set the encoding of EditText value?

I tried this but it does not seem to work.

String test = new String(myField.getText().toString().getBytes(), "Cp1251");

The receiver still has invalid value.

Vame
  • 2,033
  • 2
  • 18
  • 29

1 Answers1

0

A string is always internally (in the String class) stored as unicode.

You should specify the encoding when you convert the string to bytes, and are sending the data.

That is, invoke getBytes(String encoding) on the string, and send the resulting byte array to the receiver.

Kaj
  • 10,862
  • 2
  • 33
  • 27
  • I see. I want to send this string through socket connection. But the receiver currently cannot decode it using cp1251. Do you have any idea how to encode it properly? – Vame Jun 09 '11 at 14:09
  • @Vame. Yes, see my updated reply. I'm linking to the method that you should use. You should send the `byte[]` – Kaj Jun 09 '11 at 14:10