C # solutions to garbled characters when reading Chinese characters from the clipboard

Source: Internet
Author: User

The following code retrieves HTML-formatted text from the clipboard and finds garbled characters in the content.

If(Clipboard. ContainsText (TextDataFormat. Html ))
      TextBox1.Text = Clipboard. GetText (TextDataFormat. Html );
According to the analysis by using the Clipboard tool, HTML text is UTF-8 encoded. It seems that Clipboard. GetText () is a problem with decoding.
Complete the decoding on your own!
If(Clipboard. ContainsText (TextDataFormat. Html ))
{
      MemoryStream vMemoryStream =
              Clipboard. GetData ("Html Format ") AsMemoryStream;
      VMemoryStream. Position = 0;
      Byte[] VBytes = New byte[Vmemorystream. Length];
      Vmemorystream. Read (vbytes, 0,( Int) Vmemorystream. Length );
      Textbox1.text = encoding. utf8.getstring (vbytes );
}

The clipboard class provides a container for transferring data and objects through the clipboard. In air, the clipboard class is also used for drag-and-drop operations. Through staticgeneralClipboardProperty to access the operating system clipboard.

The clipboard object can contain the same information in multiple formats. By providing information in multiple formats, you can increase the chance that another application can use the information. UsesetData()OrsetDataHandler()Method to add data to the clipboard object.

The standard format is:

  • Bitmap_format: bitmapdata object (air only)
  • FILE_LIST_FORMAT: array of File objects (AIR only)
  • HTML_FORMAT: String data in HTML Format
  • TEXT_FORMAT: String data
  • RICH_TEXT_FORMAT: ByteArray that contains RTF data
  • URL_FORMAT: URL string (AIR only)

The clipboardformats class defines the constants used as names of standard formats.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.