11
13
2010
17

获取中文汉字拼音首字母

/*ConvertToPY v0.1 author:star date:2010-02-25 */
#include <iostream>  
#include <string>  
  
using namespace std;  
static char convert(wchar_t n); 
static bool In(wchar_t start, wchar_t end, wchar_t code); 
  
int main(int argc, char* argv[])  
{ 
    string sChinese = "取得拼音的首字母"; //   输入的字符串 
    char chr[3];  
    wchar_t wchr = 0;  
    char* buff = new char[sChinese.length()/2];  
   
    memset(buff, 0, sizeof(char)*sChinese.length()/2+1);  
    for (int i = 0, j = 0; i < (sChinese.length()/2); ++i)  
    {    
        memset(chr, 0, sizeof(chr));  
        chr[0]  = sChinese[j++];  
        chr[1]  = sChinese[j++];  
        chr[2]  = '\0';  
        wchr    = 0;  
        wchr    = (chr[0] & 0xff) << (1<<3);  
        wchr   |= (chr[1] & 0xff);  
        buff[i] = convert(wchr);  
    }  
    cout << "结果 :[" << buff << "]" << endl;  
    return 0;  
}  
char convert(wchar_t n)  
{   
    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;  
}  
inline bool In(wchar_t start, wchar_t end, wchar_t code)  
{   
    if (code >= start && code <= end)  
        return true;  
    return false;  
}

 转载自:http://star.is-programmer.com/posts/19694.html

Category: C/C++ | Tags: | Read Count: 1315
Avatar_small
Kflayca 说:
2010年11月14日 04:09

Unicode是按拼音顺序排的?

Avatar_small
seo service london 说:
2024年5月18日 18:56

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work

Avatar_small
먹튀폴리스 说:
2024年6月27日 15:24

By detoxifying and enhancing liver function, Renew offers an effective solution for weight management and fostering a healthier lifestyle.

Avatar_small
토토서치 说:
2024年6月27日 15:25

The BioLean weight loss capsule stimulates the production of fat-burning hormones in the body. By triggering thermogenesis, it raises your body temperature, leading to the burning of additional calories from fat.

Avatar_small
토동산 说:
2024年6月27日 15:26

Welcome to Aone Casino! Our casino offers top-notch technology, excellent customer service, a variety of games and a unique user experience. Thousands of visitors from all over the world enjoy exciting games at our casino.

Avatar_small
토토쿠 说:
2024年6月27日 15:27

Your blog is a treasure trove of knowledge! The importance of the topic you chose, coupled with your fresh perspective, adds a unique flavor to your content. It's always a pleasure to dive into your posts.

Avatar_small
검증나라 说:
2024年6月27日 15:27

Gain typically major outstanding things -- you should know dozens of dishes inside:

Avatar_small
먹튀클래스 说:
2024年6月27日 15:28

I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up.

Avatar_small
파워에이스 说:
2024年6月27日 15:29

Discover the pinnacle of research excellence with Direct Peptides, your trusted supplier of high-quality peptides boasting 99% purity. Experience seamless, fast global delivery and elevate your research to new heights.

Avatar_small
토스타 说:
2024年6月27日 15:29

I have been really looking for something about this subject and your writing perfectly matches my current requirements. Will you please write more along these lines? Viewers are looking for this knowledge as well as the type of unbiased opinion that you bring to the table.

Avatar_small
토디즈 说:
2024年6月27日 15:30

Renew is an exclusive dietary supplement, backed by patents, designed to purify the liver and burn liver fat. Powered by natural ingredients, including Mediterranean plants and super nutrients, it effectively addresses the root cause of stubborn belly fat.

Avatar_small
토토사이트추천 说:
2024年6月27日 15:32

elcome to Replica Watch TR, your premier destination for the finest replica watches available online.

Avatar_small
check here 说:
2024年6月27日 15:33

This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here!

Avatar_small
토토실험실 说:
2024年6月27日 15:33

The next occasion I read a weblog, I really hope which it doesnt disappoint me around that one. I am talking about, I know it was my solution to read, but I really thought youd have some thing intriguing to express. All I hear is actually a bunch of whining about something that you could fix when you werent too busy in search of attention.

Avatar_small
토토매거진 说:
2024年6月27日 15:34

I’ve been trying to find a few first rate stuff at the concern and haven't had any good fortune up till this point, You simply were given a new biggest fan!..

Avatar_small
주간토토 说:
2024年6月27日 15:35

Composed of 20 clinically tested components known for enhancing blood circulation, ZenCortex's formula promotes inner ear well-being. Each ingredient is meticulously selected to ensure the effectiveness of the dietary supplement in bolstering auditory function.

Avatar_small
탐험대 说:
2024年6月27日 15:36

thaibaccarat dot com is the best website to study casino games : like baccarat, poker, blackjack and roulette casino


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com