createfunction fn_getpy(@str
nvarchar(4000
))
returns
nvarchar(4000
)
--用於加密
--with encryption
asbegin
declare
@intlen
intdeclare
@strret
nvarchar(4000
)
declare
@temp
nvarchar(100
)
set@intlen
=len(@str
)
set@strret=''
while
@intlen
>
0begin
set@temp=''
select
@temp
=case
when
substring(@str,@intlen,1) >='帀
'then'z
'when
substring(@str,@intlen,1) >='丫
'then'y
'when
substring(@str,@intlen,1) >='夕
'then'x
'when
substring(@str,@intlen,1) >='屲
'then'w
'when
substring(@str,@intlen,1) >='他
'then't
'when
substring(@str,@intlen,1) >='仨
'then's
'when
substring(@str,@intlen,1) >='呥
'then'r
'when
substring(@str,@intlen,1) >='七
'then'q
'when
substring(@str,@intlen,1) >='妑
'then'p
'when
substring(@str,@intlen,1) >='噢
'then'o
'when
substring(@str,@intlen,1) >='拏
'then'n
'when
substring(@str,@intlen,1) >='嘸
'then'm
'when
substring(@str,@intlen,1) >='垃
'then'l
'when
substring(@str,@intlen,1) >='咔
'then'k
'when
substring(@str,@intlen,1) >='丌
'then'j
'when
substring(@str,@intlen,1) >='鉿
'then'h
'when
substring(@str,@intlen,1) >='旮
'then'g
'when
substring(@str,@intlen,1) >='發
'then'f
'when
substring(@str,@intlen,1) >='妸
'then'e
'when
substring(@str,@intlen,1) >='咑
'then'd
'when
substring(@str,@intlen,1) >='嚓
'then'c
'when
substring(@str,@intlen,1) >='八
'then'b
'when
substring(@str,@intlen,1) >='吖
'then'a
'else
rtrim(ltrim(substring(@str,@intlen,1
)))
end--對於漢字特殊字元,不生成拼音碼
if (ascii(@temp)>
127) set
@temp=''
--對於英文中小括號,不生成拼音碼
if@temp='
('or@temp='
)'set@temp=''
select
@strret
=@temp
+@strret
set@intlen
=@intlen-1
endreturn
lower(@strret
)
end
呼叫方法
select dbo.fn_getpy('漢字') py
出處:
取漢字首字母
public function hz2py byval hz as string as string dim sarr as byte system.text.encoding.default.getbytes hz dim len as integer sarr.length if len 1 t...
C 取漢字首字母
region 取中文首字母 public static string getfirstletter string paramchinese return strtemp 得到乙個漢字的拼音第乙個字母,如果是乙個英文本母則直接返回大寫字母 單個漢字 單個大寫字母 private static stri...
漢字首字母
在很多軟體中,輸入拼音的首寫字母就可以快速定位到某個詞條。比如,在鐵路售票軟體中,輸入 bj 就可以定位到 北京 怎樣在自己的軟體中實現這個功能呢?問題的關鍵在於 對每個漢字必須能計算出它的拼音首字母。gb2312漢字編碼方式中,一級漢字的3755個是按照拼音順序排列的。我們可以利用這個特徵,對常用...