【问题标题】:Encode/Decode with UTF8使用 UTF8 编码/解码
【发布时间】:2013-01-10 17:04:02
【问题描述】:

我正在尝试对富文本框中的文本进行编码,因此它显示为UTF-8
但是我遇到了一些麻烦,大多数在线帮助帖子都没有告诉我如何将转换后的文本返回到 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;
    }

【问题讨论】:

  • 你试过richTextBox1.Text = utf8.GetString(encodedBytes);吗?
  • 这实际上并没有做任何事情。你想做什么?
  • 使用 BitConverter.ToString(encodedBytes) 显示字节值。

标签: c# visual-studio-2008 utf-8 encode


【解决方案1】:

encodedBytes.ToString(encodedString); 更改为encodedString = utf8.GetString(encodedBytes);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多