标签: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();
}
}
}
标签:builder sub namespace bst append text info soft 封装
原文地址:http://www.cnblogs.com/rancrazy/p/6575592.html