# re: 获取汉字的首拼字母(java)
2008-05-07 11:45
bruceteen
根据你的思路,用C++翻写了一下
char xxx_gb2312( unsigned long word )
{
static const unsigned long areacode[] = {
0xB0A1, 0xB0C5, 0xB2C1, 0xB4EE, 0xB6EA, 0xB7A2, 0xB8C1 // a b c d e f g
, 0xB9FE, 0xBBF7, 0xBBF7, 0xBFA6, 0xC0AC, 0xC2E8, 0xC4C3 // h i j k l m n
, 0xC5B6, 0xC5BE, 0xC6DA, 0xC8BB, 0xC8F6, 0xCBFA // o p q r s t
, 0xCDDA, 0xCDDA, 0xCDDA, 0xCEF4, 0xD1B9, 0xD4D1 // u v w x y z
, 0xF7FF };
if( word>=areacode[0] && word0xA0 && (word&0xFF)<0xFF )
{
for( int i=0; i<26; ++i )
{
if( word>=areacode[i] && word
return 'A'+i;
}
}
return '?';
}
#include
std::string GetChineseSpell( const char* ptext ) // for test
{
std::string s;
for( const unsigned char* p=(const unsigned char*)ptext; *p; )
{
if( *p>0xA0 )
{
s += xxx_gb2312( p[0]<<8 | p[1] );
p += 2;
}
else
{
s += xxx_gb2312( p[0] );
p += 1;
}
}
return s;
}
#include
using namespace std;
int main( void )
{
cout << GetChineseSpell("获取汉字的首拼字母") << endl;
return 0;
}
回复 更多评论