下载代码

---------------------------------------------------------------------------------
虽然很笨的办法,却非常有效
---------------------------------------------------------------------------------
Pinyin.h
---------------------------------------------------------------------------------
#pragma once

class CPinyin
{
public:
CPinyin(void);
~CPinyin(void);
private:
CStringArray m_pyDataArray;
CString m_DataFileName;
bool m_isLoad;

public:
bool LoadData(void);
bool LoadData( CString strFileName );
CString toPinyin(CString szHanzi, int iMode=0, CString szSplit=_T(" "), CString szDuoyinziSplit=_T(",") );
};
---------------------------------------------------------------------------------
Pinyin.cpp
---------------------------------------------------------------------------------
#include "StdAfx.h"
#include "Pinyin.h"
CPinyin::CPinyin()
{
m_DataFileName = _T("PinYinData_Unicode.txt");
LoadData();
}

CPinyin::~CPinyin()
{
m_pyDataArray.RemoveAll();
}

bool CPinyin::LoadData( CString strFileName )
{
m_DataFileName = strFileName;
return LoadData();
}

bool CPinyin::LoadData(void)
{
CFile f;
CString str = _T("");
int i = 0;
int icnt = 0;
m_isLoad = false;

m_pyDataArray.RemoveAll();
if( f.Open( m_DataFileName , CFile::modeRead ) )
{
f.Seek( 2L, CFile::begin); //unicode text file keep FF FE
UINT size = (UINT)f.GetLength()-2;
TCHAR *pData = (TCHAR *)malloc( size );
if( pData != NULL )
{
f.Read( pData, size);
while(AfxExtractSubString(str,pData,i,','))
{
++i;
if( str.GetLength() > 0 )
{
str.Replace(_T(" "),_T(""));
str.Replace(_T("\r\n"),_T(""));
m_pyDataArray.Add ( str );
icnt ++;
}
}
free( pData );
}
f.Close();
}
if( icnt > 0 ) m_isLoad = true;
return m_isLoad;
}

//iMode 0 不显示多音字
// 1 显示多音字
CString CPinyin::toPinyin(CString szHanzi, int iMode, CString szSplit, CString szDuoyinziSplit )
{
int i = 0, j = 0, p1 = 0;
CString strPY = _T(""), str, strOneLine, strTmp, strHZData = _T("");
int iLen = szHanzi.GetLength();
if( iLen = 0 )
{
strHZData = strOneLine.Right(strOneLine.GetLength() - p1);
}
if( strHZData.Find( str ) != -1 )
{
isFindPinyin = true;
p1 = strOneLine.Find(_T(":"));
if( p1 > 0 )
{
strTmp = strOneLine.Left( p1 );
if( iduoyingzi > 0 )
{
if( iMode == 1 )
{
if( strPY.GetLength() > 0)
strPY += szDuoyinziSplit + strTmp;
else
strPY += strTmp;
}
}
else
{
if( strPY.GetLength()
下载代码

CPinyin unicode汉字查找拼音(支持多音字)的更多相关文章

  1. C# 汉字转拼音(支持GB2312字符集中所有汉字)

    GB2312标准共收录6763个汉字,其中一级汉字3755个,二级汉字3008个. 分区表示  GB 2312中对所收汉字进行了“分区”处理,每区含有94个汉字/符号.这种表示方式也称为区位码. )- ...

  2. C#汉字转拼音(支持多音字)

    之前由于项目需要,中间需要一个汉字转拼音和首拼的功能来做查询,感觉这种功能基本已经成熟化了,于是查找了相关的代码,首先引入眼帘的是下面两篇文章 1.C# 汉字转拼音(支持GB2312字符集中所有汉字) ...

  3. JavaScript 汉字与拼音互转终极方案 附JS拼音输入法

    转:http://www.codeceo.com/article/javascript-pinyin.html 前言 网上关于JS实现汉字和拼音互转的文章很多,但是比较杂乱,都是互相抄来抄去,而且有的 ...

  4. 【干货】JS版汉字与拼音互转终极方案,附简单的JS拼音输入法

    前言 网上关于JS实现汉字和拼音互转的文章很多,但是比较杂乱,都是互相抄来抄去,而且有的不支持多音字,有的不支持声调,有的字典文件太大,还比如有时候我仅仅是需要获取汉字拼音首字母却要引入200kb的字 ...

  5. JS版汉字与拼音互转终极方案,附简单的JS拼音输入法

    原文:http://www.cnblogs.com/liuxianan/p/pinyinjs.html 前言 网上关于JS实现汉字和拼音互转的文章很多,但是比较杂乱,都是互相抄来抄去,而且有的不支持多 ...

  6. JS版汉字与拼音互转终极方案,附简单的JS拼音

    前言 网上关于JS实现汉字和拼音互转的文章很多,但是比较杂乱,都是互相抄来抄去,而且有的不支持多音字,有的不支持声调,有的字典文件太大,还比如有时候我仅仅是需要获取汉字拼音首字母却要引入200kb的字 ...

  7. AutoCompleteTextView输入汉字拼音首字母实现过滤提示(支持多音字,Filterable的使用)

    AutoCompleteTextView具有输入提示的功能,但是它的这种提示不适合对股票列表的过滤,如果你玩过股票软件,就会知道只要输入股票名称的首字母或股票代码就会出现符合匹配的股票,这种过滤怎么实 ...

  8. SQL汉字转拼音函数-支持首字母、全拼

    SQL汉字转拼音函数-支持首字母.全拼 FROM :http://my.oschina.net/ind/blog/191659 作者不详 --方法一sqlserver汉字转拼音首字母 --调用方法 s ...

  9. Windows API方式直接调用C#的DLL,支持多音字转拼音、Gzip解压缩、公式计算(VBA、C++、VB、Delphi甚至java都可以)

    原始链接 https://www.cnblogs.com/Charltsing/p/DllExport.html 这两年,我在VBA应用方面一直有几大痛点:1.多音字转拼音:2.64位下的GZIP解压 ...

随机推荐

  1. Hive简单优化;workflow调试

    1. 定义job名字 SET mapred.job.name='customer_rfm_analysis_L1'; 这样在job任务列表里可以第一眼找到自己的任务. 2. 少用distinct, 尽 ...

  2. 【poj3233】 Matrix Power Series

    http://poj.org/problem?id=3233 (题目链接) 题意 给出一个n×n的矩阵A,求模m下A+A2+A3+…+Ak 的值 Solution 今日考试就A了这一道题.. 当k为偶 ...

  3. java中静态属性和和静态方法的继承问题 以及多态的实质

    首先结论是:java中静态属性和和静态方法可以被继承,但是没有被重写(overwrite)而是被隐藏. 静态方法和属性是属于类的,调用的时候直接通过类名.方法名完成的,不需继承机制就可以调用如果子类里 ...

  4. configure: error: Please reinstall the libcurl distribution

    configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/ 基本上 ...

  5. javax.inject中@Inject、@Named、@Qualifier和@Provider用法

    @Inject @Inject支持构造函数.方法和字段注解,也可能使用于静态实例成员.可注解成员可以是任意修饰符(private,package-private,protected,public).注 ...

  6. c++ 的vector

    使用例子:std::vector<std::string> xmlNodeList; 下面介绍-- vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组 ...

  7. 如何使用vim的帮助功能

    set guioptions+-=m/T 更换vim的默认color schema: 将下载的color.vim文件如sonofob'sidian.vim放到/usr/share/vim/vimfil ...

  8. 【原创】angularjs1.3.0源码解析之service

    Angular服务 在angular中,服务(service)是以提供特定的功能的形式而存在的. angular本身提供了很多内置服务,比如: $q: 提供了对promise的支持. $http: 提 ...

  9. 使用sql server2005全文检索

    SQL Server 2005的全文检索采用类似Lucece的技术, 为文本检索做index, 尤其适合大文本字段的检索, 性能比Lucece差一些. 著名的stackoverflow网站也使用过SQ ...

  10. NPOI在.net中的操作Excel

    1.读取 using (FileStream stream = new FileStream(@"c:\客户资料.xls", FileMode.Open, FileAccess.R ...