码迷,mamicode.com
首页 > 其他好文 > 详细

通过类库ChineseChar实现将汉字转化为拼音

时间:2017-03-18 21:18:58      阅读:1024      评论:0      收藏:0      [点我收藏+]

标签:builder   sub   namespace   bst   append   text   info   soft   封装   

//封装dll
using Microsoft.International.Converters.PinYinConverter;
using System.Text;
namespace Utils
{
public static class ChnCharInfo {
//原始
public static string ChinaCharInfoConsonant(string ToString)
{
StringBuilder SB = new StringBuilder();
foreach (char item in ToString.ToCharArray())
{
//有效
if (ChineseChar.IsValidChar(item))
{
ChineseChar China = new ChineseChar(item);
SB.Append(China.Pinyins[0]);
}
}
return SB.ToString();
}
//字母转大写去掉声调数字
public static string ChinaCharInfoUpper(string ToString)
{
StringBuilder SB = new StringBuilder();
foreach (char item in ToString.ToCharArray())
{
if (ChineseChar.IsValidChar(item))
{
ChineseChar China = new ChineseChar(item);
SB.Append(China.Pinyins[0].Substring(0,China.Pinyins[0].Length-1));
}
}
return SB.ToString();
}
//转小写
public static string ChinaCharInfoLower(string ToString)
{
StringBuilder SB = new StringBuilder();
foreach (char item in ToString.ToCharArray())
{
if (ChineseChar.IsValidChar(item))
{
ChineseChar China = new ChineseChar(item);
SB.Append(China.Pinyins[0].Substring(0, China.Pinyins[0].Length - 1).ToLower());
}
}
return SB.ToString();
}
//首字母大写
public static string ChinaCharInfoFirst(string ToString)
{
StringBuilder SB = new StringBuilder();
foreach (char item in ToString.ToCharArray())
{
if (ChineseChar.IsValidChar(item))
{
ChineseChar China = new ChineseChar(item);
string Temp = China.Pinyins[0].Substring(0, China.Pinyins[0].Length - 1);
SB.Append(Temp.Substring(0,1).ToUpper()+ (China.Pinyins[0].Substring(1, China.Pinyins[0].Length - 2)).ToLower());
}
}
return SB.ToString();
}

}
}

通过类库ChineseChar实现将汉字转化为拼音

标签:builder   sub   namespace   bst   append   text   info   soft   封装   

原文地址:http://www.cnblogs.com/rancrazy/p/6575592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!