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. IOS改变状态栏样式

    1.状态栏高亮颜色 在info.plist中添加 View controller-based status bar appearance 设置为 "NO"在AppDelegate. ...

  2. jquery选择器专题

    $(“p”).addClass(css中定义的样式类型); 给某个元素添加样式$(“img”).attr({src:”test.jpg”,alt:”test Image”}); 给某个元素添加属性/值 ...

  3. [HttpClient]简单使用GET请求

    package com.jerry.httpclient; import java.io.IOException; import org.apache.http.HttpEntity; import ...

  4. 002.AngularJs调用Restful实现CRUD

    本节我们主要给大家介绍AngularJs如何调用Restful,实现数据的CRUD. 主要用到的技术: 后端:ASP.NET WebApi + SQLServer2008 前端:AngularJs,B ...

  5. js 实现 C# 的 format 方法

    2014-11-08 12:18:51 更新,修复原形链方法被当作关键词的bug,其实之前是想用全局关键词的,不过还是算了,array里有太多单词了.                          ...

  6. Python Django开始

    1.创建工程 C:\procedure\projects>django-admin startproject mysite 2.同步数据库 C:\procedure\projects\mysit ...

  7. OpenMP 并行化处理测试

    OpenMP 并行化处理测试 #pragma omp parallel for 这条语句是用来指定后面的for循环语句变成并行执行的,将for循环里的语句变成并行执行后效率会不会提高呢?还是测试一 下 ...

  8. 转:ElasticSearch 插件安装

    原文来自于:http://www.07net01.com/linux/Elasticsearch_chajiananzhuang_21257_1350993328.html 进入elasticsear ...

  9. JavaScript注意事项

    var m = "false"; Boolean(m); // true而非 false ajax不能设置setRequestHeaders("Cookie", ...

  10. XML PULL模型

    student.xml <?xml version="1.0" encoding="utf-8"?> <stundets> <st ...