日期:2014-05-18 浏览次数:20869 次
String nativeHTMLString = @"Version:0.9 StartHTML:<<<<<<<1 EndHTML:<<<<<<<2 StartFragment:<<<<<<<3 EndFragment:<<<<<<<4 StartSelection:<<<<<<<3 EndSelection:<<<<<<<4 <!DOCTYPE> <HTML> <HEAD> <TITLE> The HTML Clipboard and special characters</TITLE> </HEAD> <BODY> <UL> <!--StartFragment --> <LI> The Fragment with special characters Ä Ö Ü ä ö ü ß 汉字</LI> <!--EndFragment --> </UL> </BODY> </HTML>"; string utf8EncodedHTMLString = Encoding.GetEncoding(0).GetString(Encoding.UTF8.GetBytes(nativeHTMLString)); StringBuilder sb = new StringBuilder(); sb.Append(utf8EncodedHTMLString); sb.Replace("<<<<<<<1", (utf8EncodedHTMLString.IndexOf("<HTML>") + "<HTML>".Length).ToString("D8")); sb.Replace("<<<<<<<2", (utf8EncodedHTMLString.IndexOf("</HTML>")).ToString("D8")); sb.Replace("<<<<<<<3", (utf8EncodedHTMLString.IndexOf("<!--StartFragment -->") + "<!--StartFragment -->".Length).ToString("D8")); sb.Replace("<<<<<<<4", (utf8EncodedHTMLString.IndexOf("<!--EndFragment -->")).ToString("D8")); string clipboardString = sb.ToString(); Clipboard.SetText(clipboardString, TextDataFormat.Html);