您的位置:首页 > 编程语言 > C#

C# 获取汉字字串的拼音声母

2009-11-07 18:39 369 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gupiao
{
class GetPinyin
{
private static char[] chrStandards = {'吖', '八' , '嚓', '咑', '妸', '发', '旮', '铪', '丌', '丌', '咔',
'垃', '嘸', '拏', '噢', '妑', '七', '呥', '仨', '他', '屲', '屲', '屲', '夕', '丫', '帀'};

public static string GetPY(string sWord)
{
string sResult = null;

foreach (char chrWord in sWord)
{
int i = 0;
if (string.Compare(chrWord.ToString(), chrStandards[0].ToString(), StringComparison.CurrentCultureIgnoreCase) >= 0)
{
for ( ; i < chrStandards.Length; i++)
{
if (string.Compare(chrWord.ToString(),chrStandards[i].ToString(),StringComparison.CurrentCultureIgnoreCase) <= 0)
{
break;
}
}
sResult = sResult + ((char)(i + 64)).ToString();
}
else
{
sResult = sResult + chrWord;
}
}
return sResult;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: