C#代码如下
using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Text.RegularExpressions;namespace Take_Out_Messy_Code{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void buttonBegin_Click(object sender, EventArgs e){//取得剪贴簿内容IDataObject dataObject = Clipboard.GetDataObject();if (dataObject.GetDataPresent(DataFormats.Rtf)){//取出RTF格式string rtf = dataObject.GetData(DataFormats.Rtf) as string;//以Regex.Replace去除多馀字元(注: 不管是否有问题,一律强制处理)string fixedRtf =Regex.Replace(rtf, @"\\uinput2(?<uc>\\u-?\d*)\s..",(m) =>{return m.Groups["uc"].Value + "?";});//另建新DataObject物件DataObject newDataObject = new DataObject();//RTF格式用修正后的字串,其馀依原值foreach (String t in dataObject.GetFormats())newDataObject.SetData(t,t == "Rich Text Format" ? fixedRtf :dataObject.GetData(t));//将修正后内容写入剪贴簿Clipboard.SetDataObject(newDataObject, true);MessageBox.Show("Take Out Pessy Code successful!");}}}}
如果觉得《VS 复制代码到word出现乱码解决办法》对你有帮助,请点赞、收藏,并留下你的观点哦!