引用 程序集
ChnCharInfo.dll
using Microsoft.International.Converters.PinYinConverter;
转换方法
public static string ToPinyin(string hanzi)
{
char[] ch = hanzi.ToArray();
string pinyinStr = "";
foreach (char c in ch)
{
if (ChineseChar.IsValidChar(c))
{
ChineseChar chineseChar = new ChineseChar(c);
ReadOnlyCollection<string> pinyin = chineseChar.Pinyins;
pinyinStr += (pinyin[0].Substring(0, pinyin[0].Length - 1));
}
else
{
pinyinStr += c.ToString();
}
}
return pinyinStr.ToLower();
}
城市绑定的特殊效果
<div id="con_province_2" style="display: none;">
<ul class="cdcomment">
@{
foreach (Entity.TXDai.Provinces item in Provinces)
{
string pinyinStr = Common.ToPinyin(item.Province);
if (pinyinStr[0] == 'a' || pinyinStr[0] == 'b' || pinyinStr[0] == 'c' || pinyinStr[0] == 'd' || pinyinStr[0] == 'f')
{
<li><a href="javascript:void(0);" data="@item.ProvinceID">@item.Province</a></li>
}
}
}
</ul>
</div>