失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > VS 复制代码到word出现乱码解决办法

VS 复制代码到word出现乱码解决办法

时间:2020-06-04 18:04:21

相关推荐

VS  复制代码到word出现乱码解决办法

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出现乱码解决办法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。