Some string operations in C #

xiaoxiao2021-03-05  22

// Get the zone 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 '); // Unicode decoding method of 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 character 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.stringbuilder SB = New System.Text.StringBuilder (""); sb.append ("i"); sb.append ("am"); ​​sb.append ("party Gun "); / string -> byte array byte [] data = system.text.encoding.ascii.getbytes (string); string -> Byte Byte Data = Convert.Tobyte (String); byte [] - > string string string = encoding.ascii.getstring (bytes, 0, nbytessize);

转载请注明原文地址:https://www.9cbs.com/read-36141.html

New Post(0)