请问谁用C#写过DLL,实现计算20902个汉字的拼音首字母?十分感谢,急问!!

renyimei 2006-06-19 10:06:09
请问谁用C#写过DLL,实现计算20902个汉字的拼音首字母?十分感谢,急问!!
...全文
675 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
rgwfeng2 2006-10-14
  • 打赏
  • 举报
回复
不错
ChengBoWu 2006-06-20
  • 打赏
  • 举报
回复
su_fisher 2006-06-20
  • 打赏
  • 举报
回复
ding~
7707 2006-06-19
  • 打赏
  • 举报
回复
/// <summary>
/// 获取一串汉字的拼音声母
/// </summary>
/// <param name="chinese">Unicode格式的汉字字符串</param>
/// <returns>拼音声母字符串</returns>
public static String Convert(String chinese)
{
char[] buffer = new char[chinese.Length];
for(int i=0; i<chinese.Length; i++)
{
buffer[i] = Convert(chinese[i]);
}
return new String(buffer);
}

/// <summary>
/// 获取一个汉字的拼音声母
/// </summary>
/// <param name="chinese">Unicode格式的一个汉字</param>
/// <returns>汉字的声母</returns>
public static char Convert(Char chinese)
{
Encoding gb2312 = Encoding.GetEncoding("GB2312");
Encoding unicode = Encoding.Unicode;

// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(new Char[] {chinese});
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, gb2312, unicodeBytes);

// 计算该汉字的GB-2312编码
int n = (int)asciiBytes[0]<<8;
n += (int)asciiBytes[1];

// 根据汉字区域码获取拼音声母
if (In(0xB0A1,0xB0C4,n)) return 'a';
if (In(0XB0C5,0XB2C0,n)) return 'b';
if (In(0xB2C1,0xB4ED,n)) return 'c';
if (In(0xB4EE,0xB6E9,n)) return 'd';
if (In(0xB6EA,0xB7A1,n)) return 'e';
if (In(0xB7A2,0xB8c0,n)) return 'f';
if (In(0xB8C1,0xB9FD,n)) return 'g';
if (In(0xB9FE,0xBBF6,n)) return 'h';
if (In(0xBBF7,0xBFA5,n)) return 'j';
if (In(0xBFA6,0xC0AB,n)) return 'k';
if (In(0xC0AC,0xC2E7,n)) return 'l';
if (In(0xC2E8,0xC4C2,n)) return 'm';
if (In(0xC4C3,0xC5B5,n)) return 'n';
if (In(0xC5B6,0xC5BD,n)) return 'o';
if (In(0xC5BE,0xC6D9,n)) return 'p';
if (In(0xC6DA,0xC8BA,n)) return 'q';
if (In(0xC8BB,0xC8F5,n)) return 'r';
if (In(0xC8F6,0xCBF0,n)) return 's';
if (In(0xCBFA,0xCDD9,n)) return 't';
if (In(0xCDDA,0xCEF3,n)) return 'w';
if (In(0xCEF4,0xD188,n)) return 'x';
if (In(0xD1B9,0xD4D0,n)) return 'y';
if (In(0xD4D1,0xD7F9,n)) return 'z';
return '\0';
}

private static bool In(int Lp, int Hp, int Value)
{
return ((Value<=Hp)&&(Value>=Lp));
}

jhtchina 2006-06-19
  • 打赏
  • 举报
回复
基本方式一样 ,修改以下就可以了
lyfer 2006-06-19
  • 打赏
  • 举报
回复
留个脚印
renyimei 2006-06-19
  • 打赏
  • 举报
回复
我并不是转换成拼音,只是需要转换一串汉字的声母,就是首写字母.
jhtchina 2006-06-19
  • 打赏
  • 举报
回复
http://jhtchina.cnblogs.com/articles/328428.html
renyimei 2006-06-19
  • 打赏
  • 举报
回复
我是公司做开发用.上面的代码有些问题想请教.请问能否给我你的qq?当然如果方便的话.谢谢
wzpwork 2006-06-19
  • 打赏
  • 举报
回复
我这有一个DLL文件,可以得到一个或几个汉字的全拼及简拼。如果你是学习可以自己好好研究一下,如果是公司做开发的,不如直接用别人已经开发的东西。很好用的。我所使用的组件的名称:ChineseToPy。楼主可以到网上找一下。
dugupiaoyun 2006-06-19
  • 打赏
  • 举报
回复
static public string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for(int i=0;i<len;i++)
{
myStr += getSpell(strText.Substring(i,1));
}
return myStr;
}


static public string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
if(arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area<<8) + pos;
int[] areacode = {45217,45253,45761,46318,46826,47010,47297,47614,48119,48119,49062,49324,49896,50371,50614,50622,50906,51387,51446,52218,52698,52698,52698,52980,53689,54481};
for(int i=0;i<26;i++)
{
int max = 55290;
if(i != 25) max = areacode[i+1];
if(areacode[i]<=code && code<max)
{
return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
}
}
return "*";
}
else return cnChar;
}

renyimei 2006-06-19
  • 打赏
  • 举报
回复
我的意思是将一串汉字转换成声母得字符串,就是首字母的字符串.这个是实现这个功能吗?
我不会VB.你会C#吗?十分谢谢! :)
rola 2006-06-19
  • 打赏
  • 举报
回复
这是用vb写的,自己转换一下吧,^_^
'获取汉字拼音第一字母
function getpychar(char)
dim tmp
tmp=65536+asc(char)
if(tmp>=45217 and tmp<=45252) then
getpychar= "A"
elseif(tmp>=45253 and tmp<=45760) then
getpychar= "B"
elseif(tmp>=45761 and tmp<=46317) then
getpychar= "C"
elseif(tmp>=46318 and tmp<=46825) then
getpychar= "D"
elseif(tmp>=46826 and tmp<=47009) then
getpychar= "E"
elseif(tmp>=47010 and tmp<=47296) then
getpychar= "F"
elseif(tmp>=47297 and tmp<=47613) then
getpychar= "G"
elseif(tmp>=47614 and tmp<=48118) then
getpychar= "H"
elseif(tmp>=48119 and tmp<=49061) then
getpychar= "J"
elseif(tmp>=49062 and tmp<=49323) then
getpychar= "K"
elseif(tmp>=49324 and tmp<=49895) then
getpychar= "L"
elseif(tmp>=49896 and tmp<=50370) then
getpychar= "M"
elseif(tmp>=50371 and tmp<=50613) then
getpychar= "N"
elseif(tmp>=50614 and tmp<=50621) then
getpychar= "O"
elseif(tmp>=50622 and tmp<=50905) then
getpychar= "P"
elseif(tmp>=50906 and tmp<=51386) then
getpychar= "Q"
elseif(tmp>=51387 and tmp<=51445) then
getpychar= "R"
elseif(tmp>=51446 and tmp<=52217) then
getpychar= "S"
elseif(tmp>=52218 and tmp<=52697) then
getpychar= "T"
elseif(tmp>=52698 and tmp<=52979) then
getpychar= "W"
elseif(tmp>=52980 and tmp<=53688) then
getpychar= "X"
elseif(tmp>=53689 and tmp<=54480) then
getpychar= "Y"
elseif(tmp>=54481 and tmp<=62289) then
getpychar= "Z"
else '如果不是中文,则不处理
getpychar=char
end if
end function
wcmj 2006-06-19
  • 打赏
  • 举报
回复
你这个人怎么这么懒哦,都给了你一个把所有的转换成拼音的了,自己把代码改一下:把连串的汉字拆成一个一个的字符串然后调我给你的方法,然后取第一个字母,不就得了,这么懒,重要的都给你帖出来了,还希望别人给全你.那还不如叫别人帮你上班编程得了.搞这行就是要动脑筋的.自己不动脑筋,以后的路都难得走.

说得对呀,别人都写到这个份上了你还要什么....
達魔 2006-06-19
  • 打赏
  • 举报
回复
dugupiaoyun(独孤飘云)说的对,帮顶一下。
renyimei 2006-06-19
  • 打赏
  • 举报
回复
呵呵,说的是哈,谢谢.:)
dugupiaoyun 2006-06-19
  • 打赏
  • 举报
回复
你这个人怎么这么懒哦,都给了你一个把所有的转换成拼音的了,自己把代码改一下:把连串的汉字拆成一个一个的字符串然后调我给你的方法,然后取第一个字母,不就得了,这么懒,重要的都给你帖出来了,还希望别人给全你.那还不如叫别人帮你上班编程得了.搞这行就是要动脑筋的.自己不动脑筋,以后的路都难得走.

110,544

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧