Common usage of strings in C #

Source: Internet
Author: User
// Obtain the location code of Chinese Characters
Byte [] array = new byte [2];
Array = system. Text. encoding. Default. getbytes ("ah ");

Int I1 = (short) (array [0]-''/0 '');
Int I2 = (short) (array [1]-''/0 '');

// Chinese character codes in Unicode decoding mode
Array = system. Text. encoding. Unicode. getbytes ("ah ");
I1 = (short) (array [0]-''/0 '');
I2 = (short) (array [1]-''/0 '');

// Unicode deserialization for Chinese Characters
String STR = "4a55 ";
String S1 = Str. substring (0, 2 );
String S2 = Str. substring (2, 2 );

Int T1 = convert. toint32 (S1, 16 );
Int t2 = convert. toint32 (S2, 16 );

Array [0] = (byte) T1;
Array [1] = (byte) T2;

String S = system. Text. encoding. Unicode. getstring (array );

// Decodes Chinese characters in the default mode
Array [0] = (byte) 196;
Array [1] = (byte) 207;
S = system. Text. encoding. Default. getstring (array );

// Obtain the string length
S = "Iam square gun ";
Int Len = S. length; // will output as 6
Byte [] Sarr = system. Text. encoding. Default. getbytes (s );
Len = Sarr. length; // will output as 3 + 3*2 = 9

// String Addition
System. Text. stringbuilder sb = new system. Text. stringbuilder ("");
SB. append ("I ");
SB. append ("am ");
SB. append ("square gun ");

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.