function pinyin(byval chinese)
chinese = replace(chinese, "/", ""): chinese = replace(chinese, "\", "")
chinese = replace(chinese, "*", ""): chinese = replace(chinese, "]", "")
chinese = replace(chinese, "[", ""): chinese = replace(chinese, "}", "")
chinese = replace(chinese, "{", ""): chinese = replace(chinese, "'", "")
chinese = getEnglish(chinese) '在这里使用getEnglish先将特殊词语转换
dim pinyinstr, istr, iIsCn, IsCn
dim pinyinconn, rs, i, x
'在这里打开拼音库
'你也可以将拼音库的并入你的程序数据库里.
on error resume next
set pinyinconn = server.createobject("Adodb.connection")
pinyinconn.open "Provider=Microsoft.Jet.OLEdb.4.0;Data Source=" & server.mappath("pinyin.Asp")
if err then pinyin = "": set pinyinconn = nothing: exit function
IsCn = true
for i = 1 to len(chinese)
iIsCn = IsCn ' 获取上次是不是中文的值
istr = Mid(chinese, i, 1)
x = Asc(istr)
if (x >= 65 and x <= 90) or (x >= 97 and x <= 122) or (x >= 48 and x <= 57) or istr = " " then
IsCn = false ' 这些是英文,数字(保留字符),不改动
if istr = " " then istr = "-"
else
set rs = pinyinconn.execute("select Top 1 [pinyin] From [pinyin] Where [content] like '%" & istr & "%';")
if not rs.eof then
istr = lcase(rs(0)): IsCn = true ' 中文
else
IsCn = false
if istr = " " then istr = "-" else istr = "" ' 将空格转换成-,如果是其他字符则清除
end if
rs.close: set rs = nothing
end if
if iIsCn = IsCn then pinyinstr = pinyinstr & istr else pinyinstr = pinyinstr & "-" & istr
pinyinstr = replace(pinyinstr, "--", "-")
pinyinstr = replace(pinyinstr, "__", "_")
next
if right(pinyinstr, 1) = "-" then pinyinstr = left(pinyinstr, len(pinyinstr) - 1)
if right(pinyinstr, 1) = "_" then pinyinstr = left(pinyinstr, len(pinyinstr) - 1)
if left(pinyinstr, 1) = "-" then pinyinstr = right(pinyinstr, len(pinyinstr) - 1)
if left(pinyinstr, 1) = "_" then pinyinstr = right(pinyinstr, len(pinyinstr) - 1)
pinyinconn.close
set pinyinconn = nothing
pinyin = trim(pinyinstr)
end Function