sp中的全角和半角之間的轉(zhuǎn)化
<%
function dbc2sbc(str, flag)
rem 全角半角轉(zhuǎn)換函數(shù)
rem flag=-1時(shí)進(jìn)行半角轉(zhuǎn)全角
rem flag=0時(shí)進(jìn)行半角全角互轉(zhuǎn)
rem flag=1時(shí)進(jìn)行全角轉(zhuǎn)半角
dim i, sstr
if len(str)<= 0 then exit function
dbc2sbc = ""
for i = 1 to len(str)
sstr = asc(mid(str, i, 1))
select case flag
case -1
if sstr>0 and sstr<= 125 then
dbc2sbc = dbc2sbc & chr(asc(mid(str, i, 1)) -23680)
else
dbc2sbc = dbc2sbc & mid(str, i, 1)
end if
case 0
if sstr>0 and sstr<= 125 then
dbc2sbc = dbc2sbc & chr(asc(mid(str, i, 1)) -23680)
else
dbc2sbc = dbc2sbc & chr(asc(mid(str, i, 1)) + 23680)
end if
case 1
if sstr<0 or sstr>125 then
dbc2sbc = dbc2sbc & chr(asc(mid(str, i, 1)) + 23680)
else
dbc2sbc = dbc2sbc & mid(str, i, 1)
end if
end select
next
end function
%>
測(cè)試代碼:
key="關(guān)鍵詞:點(diǎn)晴mis管理信息系統(tǒng) clicksun.com.cn"
response.write ""&key&""
response.write "
半角轉(zhuǎn)全角: "&dbc2sbc(key,-1)
response.write "
半角全角互轉(zhuǎn): "&dbc2sbc(key,0)
response.write "
全角轉(zhuǎn)半角: "&dbc2sbc(key,1)
該文章在 2010/7/23 0:14:33 編輯過(guò)