如何获得汉字汉语拼音的第一个字母
数据库存了大量的人名,希望能按照姓名汉语拼音第一个字母排序,并且能把姓名第一个字的汉语拼音的第一个字母显示出来,用ASP能取得汉字拼音的第一个字母吗? 问题点数:20、回复次数:14Top
1 楼SunshineRide(网魂)回复于 2005-01-20 22:41:55 得分 1
两个函数完成。
第一个函数,把汉字转化为拼音.
第二函数,把拼音的第一个字母取出来。
第一个函数需要自己写。
第二函数,VBS自带.Top
2 楼Hozaka(空虚的狼)回复于 2005-01-21 00:42:04 得分 0
中文字太多了Top
3 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-01-21 01:06:52 得分 1
其实不多
楼主要的只是中国的"姓"而已Top
4 楼qfacy(两袖清风)回复于 2005-01-21 08:34:28 得分 9
<%
response.write "<link href=style.css rel=stylesheet>"
if request.form("content")="" then
response.write "<center><form method=post action=><input name=content type=text>__<input type=submit></form>"
else
function getpychar(char)
tmp=65536+asc(char)
if(tmp>=45217 and tmp<=45252) then
getpychar= "A"
elseif(tmp>=45253 and tmp<=45760) then
getpychar= "B"
elseif(tmp>=45761 and tmp<=46317) then
getpychar= "C"
elseif(tmp>=46318 and tmp<=46825) then
getpychar= "D"
elseif(tmp>=46826 and tmp<=47009) then
getpychar= "E"
elseif(tmp>=47010 and tmp<=47296) then
getpychar= "F"
elseif(tmp>=47297 and tmp<=47613) then
getpychar= "G"
elseif(tmp>=47614 and tmp<=48118) then
getpychar= "H"
elseif(tmp>=48119 and tmp<=49061) then
getpychar= "J"
elseif(tmp>=49062 and tmp<=49323) then
getpychar= "K"
elseif(tmp>=49324 and tmp<=49895) then
getpychar= "L"
elseif(tmp>=49896 and tmp<=50370) then
getpychar= "M"
elseif(tmp>=50371 and tmp<=50613) then
getpychar= "N"
elseif(tmp>=50614 and tmp<=50621) then
getpychar= "O"
elseif(tmp>=50622 and tmp<=50905) then
getpychar= "P"
elseif(tmp>=50906 and tmp<=51386) then
getpychar= "Q"
elseif(tmp>=51387 and tmp<=51445) then
getpychar= "R"
elseif(tmp>=51446 and tmp<=52217) then
getpychar= "S"
elseif(tmp>=52218 and tmp<=52697) then
getpychar= "T"
elseif(tmp>=52698 and tmp<=52979) then
getpychar= "W"
elseif(tmp>=52980 and tmp<=53640) then
getpychar= "X"
elseif(tmp>=53689 and tmp<=54480) then
getpychar= "Y"
elseif(tmp>=54481 and tmp<=62289) then
getpychar= "Z"
else '如果不是中文,则不处理
getpychar=char
end if
end function
function getpy(str)
for i=1 to len(str)
getpy=getpy&getpychar(mid(str,i,1))
next
end function
content=request.form("content")
response.write "<center>"&getpy(content)&chr(10)
response.write "<br><br><br><a href=# onclick=javascript:history.go(-1)>返回</a>"
end if
%>Top
5 楼baikaishui_0825(baikaishui)回复于 2005-01-21 08:45:06 得分 7
汉字转拼音
http://blog.csdn.net/baikaishui_0825/archive/2005/01/19/259179.aspxTop
6 楼huhanshan013(飞兵团将军)回复于 2005-01-21 08:46:48 得分 0
关注Top
7 楼syre(神仙)回复于 2005-01-21 09:46:19 得分 0
google
Top
8 楼klions()回复于 2005-01-21 09:52:03 得分 0
好像不错也Top
9 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2005-01-21 09:54:06 得分 2
/*-1.-获得汉字字符串的首字母
根据大力的贴子改成.将大力的两个函数合并成了一个函数.
可以应用于助记码的查询
--*/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fGetPy]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fGetPy]
GO
--创建取拼音函数
create function fGetPy(@Str varchar(500)='')
returns varchar(500)
as
begin
declare @strlen int,@return varchar(500),@ii int
declare @n int,@c char(1),@chn nchar(1)
select @strlen=len(@str),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
if @chn>'z'
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='a'
set @return=@return+@c
end
return(@return)
end
go
--测试
select dbo.fgetpy('青藏高原') as 东莞市,dbo.fgetpy('ab中c国人') as 中国人
--删除拼音函数
drop function fgetpy
Top
10 楼SunshineRide(网魂)回复于 2005-01-21 09:57:29 得分 0
刚刚看了一下.很抱歉,我给了你错误的答案。
你是存放在数据库中的人名.那么,你排序的时候,根本不需要进行转换了。直接ORDER BY username就行了。
生序降序随便你。
Top
11 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2005-01-21 09:57:36 得分 0
--测试
select dbo.fgetpy('超级狼') as 超级狼,dbo.fgetpy('中国人') as 中国人
Top
12 楼SunshineRide(网魂)回复于 2005-01-21 10:04:21 得分 0
哈哈。.大狼,你理解错了啊。
他是要按照人名进行输出排序.
这根本就不需要转化汉字.直接就可以order排序了。Top
13 楼surferc((大妹子,缘分啊!))回复于 2005-01-21 16:28:07 得分 0
楼上说的对。
直接 select ...... order by 姓名字段
这里的排序规则已经自动按中文首字拼音第一个字母的顺序排列。Top
14 楼surferc((大妹子,缘分啊!))回复于 2005-01-21 16:30:35 得分 0
忘了说了首字拼音的第一字母应该做个对照表来显示(好在中国的姓氏不是很多复姓可以用第一个)。也可能有其它的方法Top




