[Materials] full-width half-width conversion [NB Alliance] (Asp, JavaScript) Code

Source: Internet
Author: User
/*
****************************
* Halfwidth <=> fullwidth *
* [NB Alliance] *
* Writer yuping *
****************************
* Parameter description:
* STR: string to be converted
* Flag: flag. The flag is converted to full at half past zero. If the flag is not 0, it is switched to half.
* Return value type: String
****************************
*/
Function dbc2sbc (STR, flag ){
VaR I;
VaR result = '';
If (Str. Length <= 0) {alert ('string parameter error'); Return false ;}
For (I = 0; I <Str. length; I ++)
{Str1 = Str. charcodeat (I );
If (str1 <125 &&! Flag)
Result + = string. fromcharcode (Str. charcodeat (I) + 65248 );
Else
Result + = string. fromcharcode (Str. charcodeat (I)-65248 );
}
Return result;
}
// Example:
Alert (dbc2sbc ("aaabc", 0 ));
Document. Write (dbc2sbc ("abcdefg", 0 )) '****************************
'* Halfwidth <=> fullwidth *
'* [NB Alliance] *
'* Writer yuping *
'****************************
'* Parameter description:
'* STR: string to be converted
'* Flag: flag. It is converted to full at half past zero. If it is not 0, it is switched to half.
'* Return value type: String
'****************************
Function dbc2sbc (STR, flag)
Dim I
If Len (STR) <= 0 then
Msgbox 'string parameter error'
Exit Function
End if
For I = 1 to Len (STR)
Str1 = ASC (mid (STR, I, 1 ))
If str1> 0 and str1 <= 125 and not flag then
Dbc2sbc = dbc2sbc & CHR (ASC (mid (STR, I, 1)-23680)
Else
Dbc2sbc = dbc2sbc & CHR (ASC (mid (STR, I, 1) + 23680)
End if
Next
End Function

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.