28,391
社区成员
发帖
与我相关
我的任务
分享
' 声明全局变量
public datastr
'获取汉字首字母函数
Function GetPY(str)
' 1、数据文件名
DataFile = "hzpy.dat"
' 2、创建FSO(对象)的字符串
FSOstr = "Scripting.FileSystemObject"
'##### ★ 代 码 开 始 ★ #####
' 忽略所有错误,默认打开
on error resume next
' 得到本文件的名字
mename=Request.ServerVariables("SCRIPT_NAME")
' 数据文件的绝对路径
thedatafile=server.MapPath(datafile)
'获取输入字符的首字母
hanzi=str
'判断是否是汉字
if abs(asc(hanzi))>127 Then '是汉字
' 创建FSO对象,读取数据文件
Set FSO = CreateObject(FSOstr)
set thefile=fso.OpenTextFile(thedatafile)
datastr=thefile.readall
thefile.close
set thefile=nothing
set fso=nothing
for i=1 to len(hanzi)
pinyin=pinyin & topy(mid(hanzi,i,1))
next
pinyin=replace(pinyin," "," ")
pinyin=trim(replace(pinyin,vbcrlf & " ",vbcrlf))
pinyin=Ucase(left(pinyin,1))
Else '不是汉字
pinyin=Mid(hanzi,1,1)
end If
'获取结束
GetPY=pinyin '返回
End Function
'****************** 自定义函数 ********************
'检查组件是否被支持的自定义函数
Function topy(strhz)
on error resume next
if asc(strhz)>0 and asc(strhz)<127 then
topy=strhz
exit function
end if
topy=strhz
thepy=split(datastr,strhz)
if ubound(split)<>0 then topy=" " & trim(left(thepy(1),instr(thepy(1),vbcrlf)-1)) & " "
End function
CREATE FUNCTION f_GetPY(@str nvarchar(4000))
RETURNS nvarchar(4000)
AS
BEGIN
DECLARE @py TABLE(
ch char(1),
hz1 nchar(1) COLLATE Chinese_PRC_CS_AS_KS_WS,
hz2 nchar(1) COLLATE Chinese_PRC_CS_AS_KS_WS)
INSERT @py SELECT 'A',N'吖',N'鏊'
UNION ALL SELECT 'B',N'八',N'簿'
UNION ALL SELECT 'C',N'嚓',N'错'
UNION ALL SELECT 'D',N'哒',N'跺'
UNION ALL SELECT 'E',N'屙',N'贰'
UNION ALL SELECT 'F',N'发',N'馥'
UNION ALL SELECT 'G',N'旮',N'过'
UNION ALL SELECT 'H',N'铪',N'蠖'
UNION ALL SELECT 'J',N'丌',N'竣'
UNION ALL SELECT 'K',N'咔',N'廓'
UNION ALL SELECT 'L',N'垃',N'雒'
UNION ALL SELECT 'M',N'妈',N'穆'
UNION ALL SELECT 'N',N'拿',N'糯'
UNION ALL SELECT 'O',N'噢',N'沤'
UNION ALL SELECT 'P',N'趴',N'曝'
UNION ALL SELECT 'Q',N'七',N'群'
UNION ALL SELECT 'R',N'蚺',N'箬'
UNION ALL SELECT 'S',N'仨',N'锁'
UNION ALL SELECT 'T',N'他',N'箨'
UNION ALL SELECT 'W',N'哇',N'鋈'
UNION ALL SELECT 'X',N'夕',N'蕈'
UNION ALL SELECT 'Y',N'丫',N'蕴'
UNION ALL SELECT 'Z',N'匝',N'做'
DECLARE @i int
SET @i=PATINDEX('%[吖-做]%' COLLATE Chinese_PRC_CS_AS_KS_WS,@str)
WHILE @i>0
SELECT @str=REPLACE(@str,SUBSTRING(@str,@i,1),ch)
,@i=PATINDEX('%[吖-做]%' COLLATE Chinese_PRC_CS_AS_KS_WS,@str)
FROM @py
WHERE SUBSTRING(@str,@i,1) BETWEEN hz1 AND hz2
RETURN(@str)
END
<%
function py(char)
zm=65536+asc(char)
if(zm>=45217 and zm<=45252) then py= "A"
if(zm>=45253 and zm<=45760) then py= "B"
if(zm>=47761 and zm<=46317) then py= "C"
if(zm>=46318 and zm<=46825) then py= "D"
if(zm>=46826 and zm<=47009) then py= "E"
if(zm>=47010 and zm<=47296) then py= "F"
if(zm>=47297 and zm<=47613) then py= "G"
if(zm>=47614 and zm<=48118) then py= "H"
if(zm>=48119 and zm<=49061) then py= "J"
if(zm>=49062 and zm<=49323) then py= "K"
if(zm>=49324 and zm<=49895) then py= "L"
if(zm>=49896 and zm<=50370) then py= "M"
if(zm>=50371 and zm<=50613) then py= "N"
if(zm>=50614 and zm<=50621) then py= "O"
if(zm>=50622 and zm<=50905) then py= "P"
if(zm>=50906 and zm<=51386) then py= "Q"
if(zm>=51387 and zm<=51445) then py= "R"
if(zm>=51446 and zm<=52217) then py= "S"
if(zm>=52218 and zm<=52697) then py= "T"
if(zm>=52698 and zm<=52979) then py= "W"
if(zm>=52980 and zm<=53640) then py= "X"
if(zm>=53689 and zm<=54480) then py= "Y"
if(zm>=54481 and zm<=55289) then py= "Z"
if(zm=56288 then py= "B"
end function
response.write py("坂")
%>
'我来回一下。不懂咱可以学。可以问。不要气馁。不过你这个提问倒是修正了我以前没注意的一个问题。
'有些汉字是有规律的,有些是没有规律的。无规律的就作为个案单写代码了。比较笨,不过可以用。
'有些大师一看就是简单问题直接回一句网上代码多什么之类的,要是找的到的话就不到CSDN里问了。回了不如不回。
<%
function py(char)
zm=65536+asc(char)
if(zm>=45217 and zm<=45252) then py= "A"
if(zm>=45253 and zm<=45760) then py= "B"
if(zm>=47761 and zm<=46317) then py= "C"
if(zm>=46318 and zm<=46825) then py= "D"
if(zm>=46826 and zm<=47009) then py= "E"
if(zm>=47010 and zm<=47296) then py= "F"
if(zm>=47297 and zm<=47613) then py= "G"
if(zm>=47614 and zm<=48118) then py= "H"
if(zm>=48119 and zm<=49061) then py= "J"
if(zm>=49062 and zm<=49323) then py= "K"
if(zm>=49324 and zm<=49895) then py= "L"
if(zm>=49896 and zm<=50370) then py= "M"
if(zm>=50371 and zm<=50613) then py= "N"
if(zm>=50614 and zm<=50621) then py= "O"
if(zm>=50622 and zm<=50905) then py= "P"
if(zm>=50906 and zm<=51386) then py= "Q"
if(zm>=51387 and zm<=51445) then py= "R"
if(zm>=51446 and zm<=52217) then py= "S"
if(zm>=52218 and zm<=52697) then py= "T"
if(zm>=52698 and zm<=52979) then py= "W"
if(zm>=52980 and zm<=53640) then py= "X"
if(zm>=53689 and zm<=54480) then py= "Y"
if(zm>=54481 and zm<=55289) then py= "Z"
end function
response.write py("坂")
'下面一行为查出对应的汉字所对应的数字码的。可以放到上面的条件语句里。
'response.write 65536+asc("坂")
以下为测试代码用的,可以看出没有什么规律
'for i=56288 to 56388
'response.write i&"-"&chr(i)
'next
%>