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

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;

}

}

}