|
#include <iostream> #include <string> using namespace std;
#define CONVERT(start, end, code, letter) if(code >= start && code <= end) return letter
char Convert(wchar_t n) { /**//// 根据汉字区域码获取拼音声母 CONVERT(0xB0A1, 0xB0C4, n, 'a'); CONVERT(0XB0C5, 0XB2C0, n, 'b'); CONVERT(0xB2C1, 0xB4ED, n, 'c'); CONVERT(0xB4EE, 0xB6E9, n, 'd'); CONVERT(0xB6EA, 0xB7A1, n, 'e'); CONVERT(0xB7A2, 0xB8c0, n, 'f'); CONVERT(0xB8C1, 0xB9FD, n, 'g'); CONVERT(0xB9FE, 0xBBF6, n, 'h'); CONVERT(0xBBF7, 0xBFA5, n, 'j'); CONVERT(0xBFA6, 0xC0AB, n, 'k'); CONVERT(0xC0AC, 0xC2E7, n, 'l'); CONVERT(0xC2E8, 0xC4C2, n, 'm'); CONVERT(0xC4C3, 0xC5B5, n, 'n'); CONVERT(0xC5B6, 0xC5BD, n, 'o'); CONVERT(0xC5BE, 0xC6D9, n, 'p'); CONVERT(0xC6DA, 0xC8BA, n, 'q'); CONVERT(0xC8BB, 0xC8F5, n, 'r'); CONVERT(0xC8F6, 0xCBF0, n, 's'); CONVERT(0xCBFA, 0xCDD9, n, 't'); CONVERT(0xCDDA, 0xCEF3, n, 'w'); CONVERT(0xCEF4, 0xD188, n, 'x'); CONVERT(0xD1B9, 0xD4D0, n, 'y'); CONVERT(0xD4D1, 0xD7F9, n, 'z'); return '\0'; }
void Test_Invert() { string sChinese = "根据汉字区域码获取汉字首字母"; // 输入汉字
wchar_t wchr = 0; int nCount = sChinese.length() / 2; char* buff = new char[nCount]; memset(buff, 0x00, sizeof(char)*nCount+1);
for (int i = 0, j = 0; i < nCount; ++i) { wchr = (sChinese[j++] & 0xff) << 8; // 高字节 wchr |= (sChinese[j++] & 0xff); // 低字节 buff[i] = Convert(wchr); }
cout << "pin yin = [ " << buff << " ]" << endl; }
|