user1967516
user1967516

Reputation:

Encode/Decode with UTF8

I am trying to encode the text in a rich text box , so it appears as UTF-8.
I am having some troubles however, and most online help posts aren't giving me how to return the converted text to the richtextbox.

  private void encodeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        UTF8Encoding utf8 = new UTF8Encoding();
        string textstring;
        string encodedString;
        textstring = richTextBox1.Text;
        byte[] encodedBytes = utf8.GetBytes(textstring);
        richTextBox1.Clear();
        encodedBytes.ToString(encodedString);
        richTextBox1.Text = encodedString;
    }

Upvotes: 0

Views: 5547

Answers (1)

Stefan P.
Stefan P.

Reputation: 9519

Change encodedBytes.ToString(encodedString); to encodedString = utf8.GetString(encodedBytes);

Upvotes: 3

Related Questions