C#使用Strings.StrConv进行简繁体转换

using  System;
using  System.Collections.Generic;
using  System.Text;
// 添加 Microsoft Visual Basic.NET Runtime 引用。
using  Microsoft.VisualBasic;
using  System.IO;

namespace  SimpleToTraditional
{
     
class  exChangeChinese
     {
         
///   <summary>
         
///  将字符串转换为简体中文
         
///   </summary>
          public   static   string  ToSimplifiedChinese( string  s)
         {
             
return  Strings.StrConv(s, VbStrConv.SimplifiedChinese,  0 );
         }

         
///   <summary>
         
///  将字符串转换为繁体中文
         
///   </summary>
          public   static   string  ToTraditionalChinese( string  s)
         {
             
return  Strings.StrConv(s, VbStrConv.TraditionalChinese,  0 );
         }

         
///   <summary>
         
///  将文件转换为简体中文
         
///   </summary>
         
///   <param name="filename"> 源文件名 </param>
         
///   <param name="outFilename"> 目标文件名 </param>
          public   static   void  ToSimplifiedChinese( string  filename,  string  outFilename)
         {
             StreamReader r 
=   new  StreamReader(filename, Encoding.GetEncoding( " gb2312 " ));
             StreamWriter w 
=   new  StreamWriter(outFilename,  false , Encoding.GetEncoding( " gb2312 " ));
             
try
             {
                 w.Write(Strings.StrConv(r.ReadToEnd(), VbStrConv.SimplifiedChinese, 
0 ));
                 w.Flush();
             }
             
finally
             {
                 w.Close();
                 r.Close();
             }
         }

         
///   <summary>
         
///  将文件转换为繁体中文
         
///   </summary>
         
///   <param name="filename"> 源文件名 </param>
         
///   <param name="outFilename"> 目标文件名 </param>
          public   static   void  ToTraditionalChinese( string  filename,  string  outFilename)
         {
             StreamReader r 
=   new  StreamReader(filename, Encoding.GetEncoding( " gb2312 " ));
             StreamWriter w 
=   new  StreamWriter(outFilename,  false , Encoding.GetEncoding( " gb2312 " ));
             
try
             {
                 w.Write(Strings.StrConv(r.ReadToEnd(), VbStrConv.TraditionalChinese, 
0 ));
                 w.Flush();
             }
             
finally
             {
                 w.Close();
                 r.Close();
             }
         }
     }
}


你可能感兴趣的:(String)