C # full-width conversion of input methods

Source: Internet
Author: User

 

/**/ ///  
/// SBC case Function)
///  
/// Any string
/// Fullwidth string
///
/// The full-width space is 12288, and the half-width space is 32. /// The correspondence between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
///
Public   String Tosbc ( String Input)
{
// Halfwidth to fullwidth:
Char [] C = Input. tochararray ();
For ( Int I =   0 ; I < C. length; I ++ )
{
If (C [I] = 32 )
{
C [I] = ( Char ) 12288 ;
Continue ;
}
If (C [I] < 127 )
C [I] = ( Char ) (C [I] + 65248 );
}
Return   New   String (C );
}

/**/ ///  
/// Function for halfwidth conversion (DBC case)
///  
/// Any string
/// Halfwidth string
///
/// The full-width space is 12288, and the half-width space is 32.
/// The correspondence between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
///
Public   String Todbc ( String Input)
{
Char [] C = Input. tochararray ();
For ( Int I =   0 ; I < C. length; I ++ )
{
If (C [I] = 12288 )
{
C [I] = ( Char ) 32 ;
Continue ;
}
If (C [I] > 65280   && C [I] < 65375 )
C [I] = ( Char ) (C [I] - 65248 );
}
Return   New   String (C );
}

 

 

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.