see to
http://dev.csdn.net/Develop/article/25/25536.shtm
http://dev.csdn.net/Develop/article/25/25536.shtm
解决方案 »
- C#怎么样从文本文件中读取指定的多个相同字符??
- c# 将xml中的数据导入dataGridView中
- Microsoft.Office.Tools和Microsoft.Office.Interop有啥区别啊?
- 也谈XmlNode和XmlElement的区别
- C# 多图同时显示,如何让图片一副一副显示?
- C#中如何将一个类的属性封装成XML文件并反封装
- C#中怎么想vc++那样正确缩进代码
- 菜鸟紧急求救,如何在winform上实现webform的table或者类似的控件
- 关于改变控件边框的颜色??急急
- Crystal Decisions已经被卖了! Crystal Report将来会怎样?!
- 新手求救三个简单问题,大家不要吝啬赐教啊,回答到一个要点都有分。
- 应该怎么学C#.Net
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
//获得汉字拼音
class class1
{
public const uint IME_REGWORD_STYLE_USER_FIRST =0x80000000;
private string result,srcstring="字";
public delegate void Mycallback(string lpszReading,uint dwStyle,string lpszString,object o);
public Mycallback myc; [DllImport("imm32.dll")]
public static extern uint ImmEnumRegisterWord( uint hkl,Mycallback lpfnEnumProc,string lpszReading, uint dwStyle,string lpszRegister, object o); //Call this to register word
public void ImmCall(string[] args)
{
myc=new Mycallback(MyCBProc);
//注册回调函数,srcstring里面存储要查的汉字
uint x=ImmEnumRegisterWord(0xE00E0804,myc,null,IME_REGWORD_STYLE_USER_FIRST+1,srcstring,null);
}
//callback函数,每次回调返回汉字的一个读音(多音字)
public void MyCBProc(string lpszReading,uint dwStyle,string lpszString,object o)
{
result+=lpszReading;
}
}
public string Extract_HZ(string HZ)
{
try
{
byte[] ZW = new byte[2];
long HZ_INT;
ZW = System.Text.Encoding.Default.GetBytes(HZ);
// get the array of byte from the single char
//int i1 = (short)(array[0] - oxa1);
//int i2 = (short)(array[1] - oxa1);
if (ZW.Length <= 1 )
{
return HZ;
}
int i1 = (short)(ZW[0]);
int i2 = (short)(ZW[1]);
HZ_INT=i1*256+i2; // expresstion
//table of the constant list
// 'A'; //45217..45252
// 'B'; //45253..45760
// 'C'; //45761..46317
// 'D'; //46318..46825
// 'E'; //46826..47009
// 'F'; //47010..47296
// 'G'; //47297..47613 // 'H'; //47614..48118
// 'J'; //48119..49061
// 'K'; //49062..49323
// 'L'; //49324..49895
// 'M'; //49896..50370
// 'N'; //50371..50613
// 'O'; //50614..50621
// 'P'; //50622..50905
// 'Q'; //50906..51386 // 'R'; //51387..51445
// 'S'; //51446..52217
// 'T'; //52218..52697
//没有U,V
// 'W'; //52698..52979
// 'X'; //52980..53640
// 'Y'; //53689..54480
// 'Z'; //54481..55289 // HZ_INT match the constant
if ((HZ_INT>=45217) && (HZ_INT<=45252))
{
return "A";
}
if ((HZ_INT>=45253) && (HZ_INT<=45760))
{
return "B";
}
if ((HZ_INT>=45761) && (HZ_INT<=46317))
{
return "C"; }
if ((HZ_INT>=46318) && (HZ_INT<=46825))
{
return "D";
}
if ((HZ_INT>=46826) && (HZ_INT<=47009))
{
return "E";
}
if ((HZ_INT>=47010) && (HZ_INT<=47296))
{
return "F";
}
if ((HZ_INT>=47297) && (HZ_INT<=47613))
{
return "G";
}
//**************************
if ((HZ_INT>=47614) && (HZ_INT<=48118))
{
//MessageBox.Show("H");
return "H";
}
if ((HZ_INT>=48119) && (HZ_INT<=49061))
{
return "J";
}
if ((HZ_INT>=49062) && (HZ_INT<=49323))
{
return "K";
}
if ((HZ_INT>=49324) && (HZ_INT<=49895))
{
return "L";
}
if ((HZ_INT>=49896) && (HZ_INT<=50370))
{
return "M";
} if ((HZ_INT>=50371) && (HZ_INT<=50613))
{
return "N"; }
if ((HZ_INT>=50614) && (HZ_INT<=50621))
{
return "O";
}
if ((HZ_INT>=50622) && (HZ_INT<=50905))
{
return "P"; }
if ((HZ_INT>=50906) && (HZ_INT<=51386))
{
return "Q"; }
//*********************
if ((HZ_INT>=51387) && (HZ_INT<=51445))
{
return "R";
}
if ((HZ_INT>=51446) && (HZ_INT<=52217))
{
return "S";
}
if ((HZ_INT>=52218) && (HZ_INT<=52697))
{
return "T";
}
if ((HZ_INT>=52698) && (HZ_INT<=52979))
{
return "W";
}
if ((HZ_INT>=52980) && (HZ_INT<=53640))
{
return "X";
}
if ((HZ_INT>=53689) && (HZ_INT<=54480))
{
return "Y";
}
if ((HZ_INT>=54481) && (HZ_INT<=55289))
{
return "Z";
}
}
catch
{
} return ("");
}
http://www.loveyuki.com/blogview.asp?logID=88&cateID=6
http://search.csdn.net/Expert/topic/2336/2336367.xml?temp=.5151636
2、求C#汉字首字母查询源码!!!!!
http://community.csdn.net/Expert/topic/2755/2755732.xml?temp=.1714899
/// 在指定的字符串列表CnStr中检索符合拼音索引字符串
/// </summary>
/// <param name="CnStr">汉字字符串</param>
/// <returns>相对应的汉语拼音首字母串</returns>
public static string GetSpellCode(string CnStr)
{
string strTemp="";
int iLen=CnStr.Length;
int i=0; for (i=0;i<=iLen-1;i++)
{
strTemp+=GetCharSpellCode(CnStr.Substring(i,1));
} return strTemp;
}
/// <summary>
/// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
/// </summary>
/// <param name="CnChar">单个汉字</param>
/// <returns>单个大写字母</returns>
private static string GetCharSpellCode(string CnChar)
{
long iCnChar;
byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);
//如果是字母,则直接返回
if (ZW.Length==1)
{
return CnChar.ToUpper();
}
else
{
// get the array of byte from the single char
int i1 = (short)(ZW[0]);
int i2 = (short)(ZW[1]);
iCnChar = i1*256+i2;
}
//expresstion
//table of the constant list
// 'A'; //45217..45252
// 'B'; //45253..45760
// 'C'; //45761..46317
// 'D'; //46318..46825
// 'E'; //46826..47009
// 'F'; //47010..47296
// 'G'; //47297..47613 // 'H'; //47614..48118
// 'J'; //48119..49061
// 'K'; //49062..49323
// 'L'; //49324..49895
// 'M'; //49896..50370
// 'N'; //50371..50613
// 'O'; //50614..50621
// 'P'; //50622..50905
// 'Q'; //50906..51386 // 'R'; //51387..51445
// 'S'; //51446..52217
// 'T'; //52218..52697
//没有U,V
// 'W'; //52698..52979
// 'X'; //52980..53640
// 'Y'; //53689..54480
// 'Z'; //54481..55289 // iCnChar match the constant
if ((iCnChar>=45217) && (iCnChar<=45252))
{
return "A";
}
else if ((iCnChar>=45253) && (iCnChar<=45760))
{
return "B";
}
else if ((iCnChar>=45761) && (iCnChar<=46317))
{
return "C";
}
else if ((iCnChar>=46318) && (iCnChar<=46825))
{
return "D";
}
else if ((iCnChar>=46826) && (iCnChar<=47009))
{
return "E";
}
else if ((iCnChar>=47010) && (iCnChar<=47296))
{
return "F";
}
else if ((iCnChar>=47297) && (iCnChar<=47613))
{
return "G";
}
else if ((iCnChar>=47614) && (iCnChar<=48118))
{
return "H";
}
else if ((iCnChar>=48119) && (iCnChar<=49061))
{
return "J";
}
else if ((iCnChar>=49062) && (iCnChar<=49323))
{
return "K";
}
else if ((iCnChar>=49324) && (iCnChar<=49895))
{
return "L";
}
else if ((iCnChar>=49896) && (iCnChar<=50370))
{
return "M";
} else if ((iCnChar>=50371) && (iCnChar<=50613))
{
return "N";
}
else if ((iCnChar>=50614) && (iCnChar<=50621))
{
return "O";
}
else if ((iCnChar>=50622) && (iCnChar<=50905))
{
return "P";
}
else if ((iCnChar>=50906) && (iCnChar<=.51386))
{
return "Q";
}
else if ((iCnChar>=51387) && (iCnChar<=51445))
{
return "R";
}
else if ((iCnChar>=51446) && (iCnChar<=52217))
{
return "S";
}
else if ((iCnChar>=52218) && (iCnChar<=52697))
{
return "T";
}
else if ((iCnChar>=52698) && (iCnChar<=52979))
{
return "W";
}
else if ((iCnChar>=52980) && (iCnChar<=53640))
{
return "X";
}
else if ((iCnChar>=53689) && (iCnChar<=54480))
{
return "Y";
}
else if ((iCnChar>=54481) && (iCnChar<=55289))
{
return "Z";
}
else return ("?");
}