ASP (JavaScript) full-width half-angle conversion code Dbc2sbc_javascript Tips

Source: Internet
Author: User
Tags chr
ASP Full-angle half-angle conversion function
Flag=-1, half angle to full angle
Flag=0 with half angle and full angle
Full angle and half angle when flag=1
Copy Code code as follows:

<%
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<= 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<= 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 version full-angle half-angle conversion function
Copy Code code as follows:

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 Common functions Sbc2dbc ()
Copy Code code as follows:

function Sbc2dbc (sStr) {
var sbc2dbc = sStr;
for (var i = < 127; i++) {
Stringfromcharcode = String.fromCharCode (i);
Switch (stringfromcharcode) {
case (':
Case ') ':
Case ' * ':
case ' + ':
Case '/':
CA Se "\":
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;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.