zoukankan      html  css  js  c++  java
  • .Net、C# 汉字转拼音,简体繁体转换方法

    Visual Studio International Pack 包含一组类库,该类库扩展了.NET Framework对全球化软件开发的支持。使用该类库提供的类,.NET 开发人员可以更方便的创建支持多文化多语言的软件应用
    下载地址:下载地址
     
    (1) (ChnCharInfo.dll)
    Simplified Chinese Pin-Yin Conversion Library
    - 支持获取简体中文字符的常用属性比如拼音,多音字,同音字,笔画数。
     
    【例如:】
    1 Microsoft.International.Converters.PinYinConverter.ChineseChar cc=new Microsoft.International.Converters.PinYinConverter.ChineseChar('');
     
     
    (2)(ChineseConverter.dll)
    Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool
    - 支持简繁体中文之间的转换。该组件还包含一个Visual Studio集成开发环境中的插件(Add-in)支持简繁体中文资源文件之间的转换。
     
    【例如:】
    --简体转换为繁体字
    1 string temp_1 = Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter.ChineseConverter.Convert("中华人民共和国", 
    2  
    3 Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter.ChineseConversionDirection.SimplifiedToTraditional);
     
    --繁体字转换为简体
    1 string temp_2 = Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter.ChineseConverter.Convert(temp_1, 
    2  
    3 Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter.ChineseConversionDirection.TraditionalToSimplified);
     
     
    (3)(EastAsiaNumericFormatter.dll)
    East Asia Numeric Formatting Library - 支持将小写的数字字符串格式化成简体中文,繁体中文,日文和韩文的大写数字字符串。
    【例如:】
    --将数字转换为大写简体中文(拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾点肆伍)
     
    1  1 string temp_4 = string.Format(new Microsoft.International.Formatters.EastAsiaNumericFormatter(), "{0:L}", 1234567890.45); 
     
    --将数字转换为小写(十二亿三千四百五十六万七千八百九十点四五)
     
    1 string temp_6 = string.Format(new Microsoft.International.Formatters.EastAsiaNumericFormatter(), "{0:Ln}", 1234567890.45);
     
    --将数字转换为货币(拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾点肆伍)
     
    1 string temp_7 = string.Format(new Microsoft.International.Formatters.EastAsiaNumericFormatter(), "{0:Lc}", 1234567890.45);

    实例代码:

    //简体/繁体切换
                string temp_1 = ChineseConverter.Convert("中国人", ChineseConversionDirection.TraditionalToSimplified);
                string temp_2 = ChineseConverter.Convert("中国人", ChineseConversionDirection.SimplifiedToTraditional);
                Console.WriteLine("简体转换:"+temp_1+"
    繁体转换:"+temp_2);
                //汉字转换拼音
                string r = string.Empty;
                Console.Write("请输入任意汉字:");
                string str = Console.ReadLine();
                foreach (char obj in str)
                {
                    try
                    {
                        ChineseChar chineseChar = new ChineseChar(obj);
                        string t = chineseChar.Pinyins[0].ToString();
                        r += t.Substring(0, t.Length - 1);
                    }
                    catch
                    {
                        r += obj.ToString();
                    }
                }
                Console.WriteLine(r.ToLower().ToString());
    

    源码:

      

    结果:

  • 相关阅读:
    try-catch- finally块中, finally块唯一不执行的情况是什么?
    Mac下 pygame.image.load不显示图片解决方法
    Ubuntu中sudo速度慢的解决方法(转载)
    [Mac Terminal] ___中断跳出死循环
    Fuzzy logic
    Discrete Mathematics and Its Applications | 1 CHAPTER The Foundations: Logic and Proofs | 1.4 Predicates and Quantifiers
    Bugs -----The largest and most interesting kind of thing.
    A Brief, Incomplete, and Mostly Wrong History of Programming Languages
    MIPS指令集
    >> 计算机的数据表示
  • 原文地址:https://www.cnblogs.com/cybing/p/5162907.html
Copyright © 2011-2022 走看看