如何按拼音首字母检索汉字?

wqnljy 2009-09-09 04:38:57
如何按拼音的首字母检索汉字,最好有个例子,谢谢大家了!

如:山东 输入字母S 或 SD 就能检索出来
...全文
702 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
missukiss02 2009-09-10
  • 打赏
  • 举报
回复
mark
风之影子 2009-09-10
  • 打赏
  • 举报
回复
如果是前台处理,先提取数据再转换拼音。

如果是后台处理,效率高一些。(利用上面函数的取数,在表里添加一列拼音简写列)
风之影子 2009-09-10
  • 打赏
  • 举报
回复
C#代码

 /// <summary>
/// /// 取单个字符的拼音声母/// Code By MuseStudio@hotmail.com
/// /// 2004-11-30/// </summary>/// <param name="c">要转换的单个汉字</param>
/// /// <returns>拼音声母</returns>
public static string GetPYChar(string c)
{

byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(ClearNullFunction(c));
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
if (i < 0xB0A1) return "*";
if (i < 0xB0C5) return "a";
if (i < 0xB2C1) return "b";
if (i < 0xB4EE) return "c";
if (i < 0xB6EA) return "d";
if (i < 0xB7A2) return "e";
if (i < 0xB8C1) return "f";
if (i < 0xB9FE) return "g";
if (i < 0xBBF7) return "h";
if (i < 0xBFA6) return "j";
if (i < 0xC0AC) return "k";
if (i < 0xC2E8) return "l";
if (i < 0xC4C3) return "m";
if (i < 0xC5B6) return "n";
if (i < 0xC5BE) return "o";
if (i < 0xC6DA) return "p";
if (i < 0xC8BB) return "q";
if (i < 0xC8F6) return "r";
if (i < 0xCBFA) return "s";
if (i < 0xCDDA) return "t";
if (i < 0xCEF4) return "w";
if (i < 0xD1B9) return "x";
if (i < 0xD4D1) return "y";
if (i < 0xD7FA) return "z";
return "*";
}
#endregion
风之影子 2009-09-10
  • 打赏
  • 举报
回复
SQL函数取汉字拼音首字母

create function comm_getpy
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin

declare @word nchar(1),@PY nvarchar(4000)

set @PY=''

while len(@str)>0
begin
set @word=left(@str,1)

--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
泡面之夏 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cat_hsfz 的回复:]
你可以用码表,把用户输入的中文先转成拼音,再专门保存到一个字段。
[/Quote]
yuanmanguo 2009-09-10
  • 打赏
  • 举报
回复
mark
wqnljy 2009-09-10
  • 打赏
  • 举报
回复
谢谢大家了!
netniule 2009-09-09
  • 打赏
  • 举报
回复
如果只是地名,就在数据库中存放所有地名及拼音首字母
不是地名就不知道了
cat_hsfz 2009-09-09
  • 打赏
  • 举报
回复
你可以用码表,把用户输入的中文先转成拼音,再专门保存到一个字段。
柳晛 2009-09-09
  • 打赏
  • 举报
回复
地名啊,提前填进去的...
bychgh 2009-09-09
  • 打赏
  • 举报
回复

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧