C#获取字符拼音首字母,可以存储在数据库中以备将来按字母搜索的需求。

public static string GetAc(string s)
{
try
{
string temp = Service.Text.Chinese2Spell.MakeSpellCode(s, Service.Text.SpellOptions.EnableUnicodeLetter).ToUpper();
if (temp.Length > )
return temp.Substring(, );
return temp;
}
catch
{
return "";
}
}

sql端进行处理

create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='')
returns varchar(500)
as
begin /*函数实现开始*/
declare @strLen int,@return varchar(500),@i int
declare @n int,@c char(1),@chn nchar(1)
select @strLen=len(@strChinese),@return='',@i=0
while @i<@strLen
begin /*while循环开始*/
select @i=@i+1,@n=63,@chn=substring(@strChinese,@i,1)
if @chn>'z'/*原理:“字符串排序以及ASCII码表”*/
select @n = @n +1,@c =case chn when @chn then char(@n) else @c end from(select top 27 * from (select chn = '吖' union all select '八' union all select '嚓' union all select '咑' union all select '妸' union all select '发' union all select '旮' union all select '铪' union all select '丌' /*because have no 'i'*/ union all select '丌' union all select '咔' union all select '垃' union all select '嘸' union all select '拏' union all select '噢' union all select '妑' union all select '七' union all select '呥' union all select '仨' union all select '他' union all select '屲' /*no 'u'*/ union all select '屲' /*no 'v'*/ union all select '屲' union all select '夕' union all select '丫' union all select '帀' union all select @chn) as a order by chn COLLATE Chinese_PRC_CI_AS ) as b
else
set @c=@chn
set @return=@return+@c
end /*while循环结束*/
return(@return)
end /*函数实现结束*/
--调用
select dbo.[fn_ChineseToSpell]('你好')

C#&Sql获取中文字符拼音首字母的方法的更多相关文章

  1. php 获取中文字符拼音首字母

    //php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...

  2. php获取中文字符拼音首字母

    //php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){ return ''; } $fchar = ord($str{0}) ...

  3. sql获取汉字的拼音首字母的函数

    ql获取汉字的拼音首字母   if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...

  4. java 获取中文字符的首字母

    原理: GB2312编码中的中文是按照拼音排序的 注意: 一些生僻的字无法获得正确的首字母,原因是这些字都是后加入的. import java.io.UnsupportedEncodingExcept ...

  5. js 获取中文的拼音首字母

    es6 + 模块化封装 "use strict"; module.exports = { //参数,中文字符串 //返回值:拼音首字母串数组 makePy (str) { if ( ...

  6. sql获取汉字的拼音首字母

    if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN' ...

  7. php获取汉字拼音首字母的方法

    现实中我们经常看到这样的说明,排名不分先后,按姓名首字母进行排序.这是中国人大多数使用的排序方法.那么在php程序中该如何操作呢? 下面就分享一下在php程序中获取汉字拼音的首字母的方法,在网上搜到的 ...

  8. C# 获取汉字的拼音首字母和全拼(含源码)

    C# 获取汉字的拼音首字母 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手 ...

  9. (转载)delphi中获取汉字的拼音首字母

    delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...

随机推荐

  1. 『重构--改善既有代码的设计』读书笔记----Extract Method

    在编程中,比较忌讳的一件事情就是长函数.因为长函数代表了你这段代码不能很好的复用以及内部可能出现很多别的地方的重复代码,而且这段长函数内部的处理逻辑你也不能很好的看清楚.因此,今天重构第一个手法就是处 ...

  2. Mysql 源码编译教程贴

    题外话:这是一篇教程贴,不仅学的是mysql的编译,还是一些编译的知识.我也是一个菜鸟,写一些感悟和心得,有什么问题可以批评指正,谢谢! 如果只是为了安装请移到我的另一篇安装贴: Mysql安装贴 环 ...

  3. ubuntu忘记登录账户以及密码

    笔者在诸多方面仍然是初学者.感兴趣的方面也很多,电脑装上ubuntu14.04也有一段时间了,但仍然在不断学习更多基础的东西. 因为对于命令行界面还有些不习惯,所以一直依赖于图形界面,需要使用终端的时 ...

  4. 理解O/R Mapping

    本文的目的是以最精炼的语言,理解什么是O/R Mapping,为什么要O/R Mapping,和如何进行O/R Mapping. 什么是O/R Mapping? 广义上,ORM指的是面向对象的对象模型 ...

  5. 破解Inode客户端使用笔记本共享WIFI

    由于住在学校的公寓里面,所以使用的是校园网,但是校园网限制了无线的使用,强制所有网络用户使用INode网络客户端,这个客户端不但很丑很难看,而且每天联网十分费劲,费了半天的力气终于联上网了,可是一眨眼 ...

  6. oracle操作字符串:拼接、替换、截取、查找

    1.拼接字符串 1)可以使用“||”来拼接字符串 select '拼接'||'字符串' as str from dual 2)通过concat()函数实现 select concat('拼接', '字 ...

  7. python学习第十六天 --继承进阶篇

    这一章节主要讲解面向对象高级编程->继承进阶篇,包括类多继承介绍和继承经典类和新式类属性的查找顺序不同之处. 多继承 上一章节我们讲到继承,子类继承父类,可以拥有父类的属性和方法,也可以进行扩展 ...

  8. 浅谈Android序列化

    序列化原因 序列化的原因基本可以归纳为以下三种情况: 永久性保存对象,保存对象的字节序列到本地文件中: 对象在网络中传递: 对象在IPC间传递. --- --- 序列化方法 在Android系统中关于 ...

  9. Python二分查找

    代码: 时间复杂度:O(log2n) #!/usr/bin/env python #coding:utf-8 import copy from copy import deepcopy ''' def ...

  10. 一个jpa动态模糊查询的实现

    最近一直在是用spring data jpa,使用起来确实方便,如果是单表的操作基本上通过方法名都可以实现,下面是一个 Specification 实现动态模糊查询的例子这个查询是通过JpaSpeci ...