C# 通过拼音检索中文名称
转自:http://blog.csdn.net/wu_zheng_peng/article/details/8639828
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace TextEdit
{
public partial class Form1 : Form
{
public ArrayList list = new ArrayList();
public Form1()
{
InitializeComponent();
addList();//添加集合中文
}
private void tBox_TextChanged(object sender, EventArgs e)
{
this.lstBox.Items.Clear();
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[^a-zA-Z\r\n]+");
if (!reg.Match(tBox.Text).Success)
{
//遍历ArrayList中的所有信息
foreach (object obj in list)
{
//获得各汉字拼音首字母缩写
string strName = GetChineseSpell(obj.ToString()).ToLower();
string strTxtName = tBox.Text.ToLower();
//根据拼音进行匹配
if (strName.Contains(strTxtName) && strName.Substring(0, strTxtName.Length) == strTxtName)
{
lstBox.Items.Add(obj);
}
}
return;
}
//检索信息为空,就显示所有信息
lstBox.DataSource = list;
}
/// <summary>
/// 拼音检索
/// </summary>
/// <param name="strText"></param>
/// <returns></returns>
static public string GetChineseSpell(string strText)
{
int len = strText.Length;
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < len; i++)
strBuilder.Append(getLetters(strText.Substring(i, 1)));
return strBuilder.ToString();
}
/// <summary>
/// 得到首字母
/// </summary>
/// <param name="strChar"></param>
/// <returns></returns>
public static string getLetters(string strChar)
{
byte[] byteLetters = Encoding.Default.GetBytes(strChar);
if (byteLetters.Length > 1)
{
int first = (short)byteLetters[0];
int second = (short)byteLetters[1];
int code = (first << 8) + second;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
return string.Empty;
}
else
return strChar;
}
public void addList()
{
list.Add("奇元");
list.Add("玉环");
list.Add("曹操");
list.Add("曹丕");
list.Add("常在");
list.Add("常义");
list.Add("张三四");
}
}
}
转载于:https://www.cnblogs.com/zjw520/archive/2013/04/24/3039937.html
C# 通过拼音检索中文名称相关推荐
- ElasticSearch学习(四)—— 中文按拼音排序拼音检索
使用pinyin分词器 下载拼音分词器https://github.com/medcl/elasticsearch-analysis-pinyin 解压进入目录elasticsearch-analys ...
- linux 进入汉字目录,终端下拼音补全中文名称和路径
{ 撰文/BiFF } 在 Linux 下打字飞快的朋友,遇到中文目录和文件名立马就慢下来了, 有 2 种选择: 切换成中文输入一两个汉字,然后按 TAB 补全 动用鼠标复制 现在有第三种选择了 :) ...
- 支持拼音检索的TextBox扩展控件-使用
我的上一个支持拼音检索的TextBox扩展控件,由于有些网友留言和发邮件问如何用, 如:菜鸟AAA等当时想到肯定大家都会用,就没上传示例程序. 原文为:http://www.cnblogs.com/w ...
- Solr之拼音检索。
拼音检索中国人的专用检索,例如:中文内容为"中国"的输入 "zhongguo"."zg"."zhonggu 全拼".&q ...
- Mysql 中文名称(包括字母)按首字母排序
如果中文名称字段只有汉字那么排序只加个 CONVERT(name USING gbk ) COLLATE gbk_chinese_ci asc 就可以. 现在要排序的字段既有中文也有字母还有特殊字符串 ...
- 目前比较全面且实用的Java中文名称批量生成器
目前比较全面且实用的Java中文名称批量生成器 目前比较全面且实用的Java中文名称批量生成器 生成结果 实现功能 关键代码 通过等比数列实现百家姓常用姓氏的概率翻倍 目前比较全面且实用的Java中文 ...
- 集合(7)——Dictionary字典(2)——C#中的拼音检索
1.为什么要用拼音检索?坐席只能根据客户的语言进行判断,无法准确写对姓名. 2.Visual Studio International Pack 3.练习:根据文档学习使用方法.发下安装包自己探索.目 ...
- matlab各名称,Matlab-Simulink各模块对应的中文名称及介绍
<Matlab-Simulink各模块对应的中文名称及介绍>由会员分享,可在线阅读,更多相关<Matlab-Simulink各模块对应的中文名称及介绍(20页珍藏版)>请在人人 ...
- Eclipse的SVN插件移动中文名称文件提示org.tigris.subversion.javahl.ClientException: Bogus URL...
今天一个同事使用Eclipse的SVN插件,在"SVN资源库"视图,移动一个中文名称的文件,提示org.tigris.subversion.javahl.ClientExcepti ...
最新文章
- 三种方法实现CSS三栏布局
- 虚拟机上Redhat linux9.0的VMware Tools详细图文教程
- LightOJ1032 Fast Bit Calculations(数位DP)
- Java书籍Top 10
- SSH HTTPS 公钥、秘钥、对称加密、非对称加密、 总结理解
- 前端学习(2788):完成图片商品数据页面渲染
- axure原件 总是丢失_Axure实现提示文本单击显示后自动消失的效果
- 极光实时监听怎么调用_源码分析 Sentinel 实时数据采集实现原理(图文并茂)
- windows10资讯和兴趣怎么关闭?
- 我为什么辞去 Netflix 价值 45 万美元的开发工作
- hue 安装 + authrization manager安装
- [常微分方程的数值解法系列一] 常微分方程
- Ant Design Vue - 修改<Table>表格组件默认的暂无数据图标(自定义表格空数据状态图片)
- jeesit的使用(一)
- ArcCatalog中连接SDE数据库
- 决策树实现手写体识别
- 小学计算机座位安排表,戳痛父母们的班级座位表,安排孩子怎么坐也是一门学问...
- node之cookie-parser
- linux练习题十七
- spring mysql 事务回滚失败_Spring事务回滚失败
热门文章
- 驳!?使用游戏引擎是作弊行为的5个依据
- 手游引擎之战再现新挑战者,OGEngine来了
- pmp每日三题(2022年2月17日)
- MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
- RunTime类,后台快速打开浏览器
- 高考完?入门级的开源项目带你开启编程之旅
- tomcat的日志文件权限与启动用户的权限不一致
- c++输入输出流加速器
- chrome浏览器被reimage pair 劫持怎么处理
- NewSQL数据库VoltDB特性简介