国际化似乎是一个非常流行的口号了,一个网站没有英文版至少也要弄个繁体版,毕竟都是汉字,翻译起来不会那么麻烦:p
一般的繁简转换是使用字典,通过gb的内码算出big5字符在字典中的位置,读取显示之,用fso应该可以实现。这里介绍的方法思路更简单一些,用dictionary对象,就是字典,呵呵,dicgb2big5(gb)就是对应的big5。比起计算内码再按照位置读取字符简单的多吧:)
为了减少开销,把字典放在application中,即在global.asa中建立两个application的字典对象
<object id=objgb2big5 progid="scripting.dictionrary" runat="server" scope="application">
</object>
<object id=objbig52gb progid="scripting.dictionrary" runat="server" scope="application">
</object>
在application_onstart中给字典添加项目
……
objgb2big5.add "啊", "摆"
objgb2big5.add "阿", ""
objgb2big5.add "埃", "甁"
……
……
objbig52gb.add "摆", "啊"
objbig52gb.add "", "阿"
objbig52gb.add "甁", "埃"
……
字典项很多,就不都写了
做好了字典,使用的时候只要查一下就行了:)
function gb2big5(str)
dim i, l, k, t, rtn
l = len(str)
rtn=""
for i=1 to l
k = mid(str, i, 1)
if ascw(k)>=0 and ascw(k)<128 then
t = k
else
if objgb2big5.exists(k) then
t = objgb2big5.item(k)
else
t = " "
end if
end if
rtn = rtn & t
next
gb2big5 = rtn
end function
function big52gb(str)
dim i, l, k, t, rtn
l = len(str)
rtn=""
for i=1 to l
k = mid(str, i, 1)
if ascw(k)>=0 and ascw(k)<128 then
t = k
else
if objbig52gb.exists(k) then
t = objbig52gb.item(k)
else
t = " "
end if
end if
rtn = rtn & t
next
big52gb = rtn
end function
测试一下看看吧
<%=gb2big5("繁简转换测试")%>
下面的网站就是用这种方法实现的
http://tingfei.com 繁简转换的链接在页面左上角
