Halfwidth and fullwidth Interchange

Source: Internet
Author: User
Due to the restrictions on Field Types in some databases corresponding to txtbox, sometimes when full-angle characters are written in, a problem may occur during statistics query.

It is better to switch. You can choose to convert the full angle into a half angle before saving it, And then store it in, so there will be no problem during statistics. 1 Halfwidth Interchange # Region Halfwidth Interchange
2 /**/ /// <Summary>
3 /// SBC case Function)
4 /// </Summary>
5 /// <Param name = "input"> Any string </Param>
6 /// <Returns> Fullwidth string </Returns>
7 /// <Remarks>
8 /// The full-width space is 12288, and the half-width space is 32.
9 /// The correspondence between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
10 /// </Remarks>
11 Public Static String Tosbc ( String Input)
12 {
13 // Halfwidth to fullwidth:
14 Char [] C = Input. tochararray ();
15 For ( Int I = 0 ; I < C. length; I ++ )
16 {
17 If (C [I] = 32 )
18 {
19 C [I] = ( Char ) 12288 ;
20 Continue ;
21 }
22 If (C [I] < 127 && C [I] > 32 )
23 {
24 C [I] = ( Char ) (C [I] + 65248 );
25 }
26 }
27 Return New String (C );
28 }
29
30 /**/ /// <Summary>
31 /// Function for halfwidth conversion (DBC case)
32 /// </Summary>
33 /// <Param name = "input"> Any string </Param>
34 /// <Returns> Halfwidth string </Returns>
35 /// <Remarks>
36 /// The full-width space is 12288, and the half-width space is 32 (spaces are not required here)
37 /// The correspondence between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
38 /// </Remarks>
39 Public Static String Todbc ( String Input)
40 {
41 Char [] C = Input. tochararray ();
42 For ( Int I = 0 ; I < C. length; I ++ )
43 {
44 If (C [I] = 12288 )
45 {
46 C [I] = ( Char ) 32 ;
47 Continue ;
48 }
49 If (C [I] > 65280 && C [I] < 65375 )
50 {
51 C [I] = ( Char ) (C [I] - 65248 );
52 }
53 }
54 Return New String (C );
55 }
56 # Endregion

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.