转自lance的:http://hi.baidu.com/lancy/blog/item/71b2b17e7151b63e0dd7da1e.html
本方法运用Microsoft.Office.Interop.Word.dll所制作,采用word的转换方式,所以转换后会得到繁体的台湾词汇组成的文字,如
getstr("网络打印机打印数据") 会返回
"網路印表機列印資料"
使用时不要忘了添加对Microsoft.Office.Interop.Word.dll的引用
Code
string getstr(string asInput)
{
Object template = Type.Missing;
Object newTemplate = Type.Missing;
Object documentType = Type.Missing;
Object visible = Type.Missing;
Microsoft.Office.Interop.Word.Application aWord = null;
Document doc = null;
Object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
Object originalFormat = Type.Missing;
Object routeDocument = Type.Missing;
string sAsInputtemp = asInput;
try
{
aWord = new Microsoft.Office.Interop.Word.Application();
doc = aWord.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
aWord.Selection.TypeText(asInput);
//繁体文字转换成为简体文字,逐词转换
aWord.Selection.Range.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
aWord.ActiveDocument.Select();
sAsInputtemp = aWord.Selection.Text;
}
catch (COMException ex)
{
throw ex;
}
finally
{
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
aWord.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
return sAsInputtemp;
}