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. Java基础--IO

    1,流的认识和分类 2,Java种处理流的IO类架构 3,字节流和字符流转换 4,NIO的概述 5,Java IO关闭资源 1,流的认识和分类 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的 ...

  2. WebService笔记-Schema约束

                        Schema约束 俗话说得好 好记性不如烂笔头. 看了下WebService视频,觉得还是得下笔记. 观看的视频地址:http://edu.51cto.com/ ...

  3. fedora 安装nginx+php+mysql

    环境 fedora 最新版 20 参考:http://www.cnblogs.com/beceo/archive/2012/08/21/2648378.html ------------------- ...

  4. jquery hide() show()

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. php防止SQL注入详解及防范

    SQL 注入是PHP应用中最常见的漏洞之一.事实上令人惊奇的是,开发者要同时犯两个错误才会引发一个SQL注入漏洞一个是没有对输入的数据进行过滤(过滤输入),还有一个是没有对发送到数据库的数据进行转义( ...

  6. spring mvc 自定义Handlermapping

    上次大概写了个可以解决velocity 多视图的东西. 但是实际运用过程中又到处找了些资料看了下.这里 小计下: DispatcherServlet解析过程: ..1..HandlerMapping. ...

  7. DIV+CSS两种盒子模型

    盒子模型有两种,分别是 IE 盒子模型和标准 W3C 盒子模型.他们对盒子模型的解释各不相同, 先来看看我们熟悉的标准盒子模型: 从上图可以看到标准 W3C 盒子模型的范围包括 margin.bord ...

  8. Hibernate的查询语言之HQL(一)——快速入门

    Hibernate提供异常强大的查询体系,使用Hibernat有多种查询方式可以选择:即可以使用Hibernate的HQL查询,也可以使用条件查询,甚至可以使用原生的SQL查询语句.不仅如此, Hib ...

  9. j2ee爬坑行之二 servlet

    servlet生命周期 web容器加载servlet 类 web容器调用servlet的构造函数,初始化servlet. web容器调用servlet的init()方法.注意该方法在servlet的一 ...

  10. C#程序设计基础——常量

    C#程序设计基础——常量 常量是在编译时已知,并且在程序的生存期内不发生更改的不可变值.常量使用const修饰符进行声明. 常量必须在声明时初始化,且常量的类型必须为以下类型之一:sbyte/byte ...