Some string operations in C #

zhaozj2021-02-16  55

// get 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');

// unicode decoding method

Array = system.text.Encoding.uitode.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.uitode.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 = 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 Rifle");

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

New Post(0)