Some string operations in C #

zhaozj2021-02-16  103

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 mode The Chinese characters array = system.text.Encoding.unicode.getbytes ("ah"); I1 = (short) (Array [0] - '' / 0 '); i2 = (Short) (Array [1] - '' / 0 '');

// unicode antique code is 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.uitode.getstring (array);

// Default method is a 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 = SARR. 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 ("square gun ");

/

supplement:

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-10894.html

New Post(0)