|
flag=-1時(shí)進(jìn)行半角轉(zhuǎn)全角
flag=0時(shí)進(jìn)行半角全角互轉(zhuǎn)
flag=1時(shí)進(jìn)行全角轉(zhuǎn)半角
復(fù)制代碼 代碼如下:
<%
Function DBC2SBC(Str, flag)
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
%>
Javascript版 全角半角轉(zhuǎn)換函數(shù)
復(fù)制代碼 代碼如下:
function dbc2sbc(sStr){
var dbc2sbc = sStr;
for (var i = 65281; i < 65375; i++) {
var re = new RegExp(String.fromCharCode(i), "g");
var va = String.fromCharCode(i - 65248);
dbc2sbc = dbc2sbc.replace(re, va);
}
dbc2sbc = dbc2sbc.replace(/ /g, ' ');
return dbc2sbc;
}
Javascript常用函數(shù) sbc2dbc()
復(fù)制代碼 代碼如下:
function sbc2dbc(sStr){
var sbc2dbc = sStr;
for (var i = 33; i < 127; i++) {
stringFromCharCode = String.fromCharCode(i);
switch (stringFromCharCode) {
case "(":
case ")":
case "*":
case "+":
case "/":
case "http://":
case "[":
case "]":
case "?":
case "$":
case ".":
case "^":
case "|":
stringFromCharCode = '//' + stringFromCharCode;
default:
break;
}
var re = new RegExp(stringFromCharCode, "g");
var va = String.fromCharCode(i + 65248);
sbc2dbc = sbc2dbc.replace(re, va);
}
sbc2dbc = sbc2dbc.replace(/ /g, ' ');
return sbc2dbc;
}
JavaScript技術(shù):asp(javascript)全角半角轉(zhuǎn)換代碼 dbc2sbc,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。