32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace ZWL.Common
|
|
{
|
|
public class HanZi2PinYin
|
|
{
|
|
public static string ConvertToPinYin(string str)
|
|
{
|
|
string PYstr = "";
|
|
foreach (char item in str.ToCharArray())
|
|
{
|
|
if (Microsoft.International.Converters.PinYinConverter.ChineseChar.IsValidChar(item))
|
|
{
|
|
Microsoft.International.Converters.PinYinConverter.ChineseChar cc = new Microsoft.International.Converters.PinYinConverter.ChineseChar(item);
|
|
|
|
//PYstr += string.Join("", cc.Pinyins.ToArray());
|
|
PYstr += cc.Pinyins[0].Substring(0, 1).ToLower();
|
|
//PYstr += cc.Pinyins[0].Substring(0, cc.Pinyins[0].Length - 1).Substring(0, 1).ToLower();
|
|
}
|
|
else
|
|
{
|
|
PYstr += item.ToString();
|
|
}
|
|
}
|
|
return PYstr;
|
|
}
|
|
}
|
|
}
|