zoukankan      html  css  js  c++  java
  • 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();
                 }
             }
         }
    }


  • 相关阅读:
    Membership provider Role provider 机制详解
    android Toast大全(五种情形)建立属于你自己的Toast
    android:scaleType属性
    Android接收短信同时获取短信内容
    JAVA三大框架的各自作用
    Android短信监听器
    ImageView / ImageButton 图片太大或者太小解决方法
    Android LayoutInflater详解
    Android开发之Intent.Action
    Android实现短信监听并且转发到指定的手机号,转发后不留痕
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1768926.html
Copyright © 2011-2022 走看看