最新评论

re: 一个词组转化成拼音的函数 GeorgeHuang 2009-04-25 10:58  
下面是我对上面的修改,测试了一下,已经可以对标点符号、数字、字母、中文、和特殊字符进行区分了,不过结果看上去还是不怎么顺眼,比如拆分“a安”,那最后结果会变成aan,这样对以后的处理有一定的影响,但以目前的水平我不知道怎样解决。希望看过我写的函数以后多多指点。

alter function streetii_PinYin_Convert_Class
(
@word nvarchar(128)
)
returns @temp table
(
id int identity(1,1),
word nvarchar(128),
pinyin nvarchar(255)
)
as
begin
declare @pinyin nvarchar(16)
declare @char nvarchar(4)
declare @currentindex int=1
declare @totalpinyin nvarchar(256)=''
declare @length int=len(@word) --检测字符串的长度

if @word is not null
begin
while @currentindex<=@length
begin
set @char=substring(@word,@currentindex,1)--逐个字符拆分,并赋值给变量@char
if unicode(@char) between 19968 and 40869 --为汉字
begin
set @pinyin =(select pinyin from streetii_pinyinforword where word=@char)--获取@char里面的字符的拼音
set @totalpinyin=@totalpinyin+@pinyin--加入到变量中
end
else --不为汉字,原样输出
begin
set @totalpinyin=@totalpinyin+@char
end
set @currentindex=@currentindex+1--检测下一个汉字
end
insert into @temp values(@word,@totalpinyin)
end
return
end


/*
select * from streetii_PinYin_Convert_Class ('北1京,2欢a迎@你!')
*/
按你的谬论就是说根本不需要任何准则咯,完全自己弄自己的就行啦?这样软件工程,W3C 那些有必要存在吗?理论来源于实践,听过没?没有就回去看看书吧。别在这里丢人现眼。
简直是放屁,任何事情都要看实际情况。