C #, some common usage string operation [2004-08-21 10:47 AM | Author: admin | From: Mencius Chapter E] // get the area code byte characters [] array = new byte [2]; array = System.Text.Encoding.default.getbytes ("ah"); int I1 = (short) (Array [0] - '' / 0 '); int I2 = (short) (Array [1] -' '/ 0 ''); // Unicode decoding method in the Chinese characters array = system.text.Encoding.unicode.getbytes ("ah"); I1 = (short) (Array [0] - '' / 0 '); I2 = (SHORT) (Array [1] - '' / 0 '); // Unicode anticode is Chinese character 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); // default method anti-decoding is Chinese characters array [0] = (byte) 196; array [1] = (byte) 207; s = system.text .Encoding.default.getstring (array); // Take the string length s = "IAM square gun"; int Len = s.Length; // Will Output as 6 byte [] SARR = system.text.Encoding.default .Getbytes (s); len = sar.Length; // Will Output AS 3 3 * 2 = 9 // String plus system.text.stract.StringBuilder SB = new system.text.StringBuilder (""); SB. Append (" I "); sb.append (" am "); sb.append (" square gun "); / string -> Byte array byte [] data = syste.text.encoding.ascii.getbytes (string); string; string; string; string; string -> BytebyTe Data = Convert.Tobyte (String); Byte [] -> StringString String = Encoding.ascii.getstring (Bytes, 0, Nbytesize);