asp.net is a string manipulation method

  • 2020-05-12 02:26:19
  • OfStack

string fox;
fox.ToLower () to lowercase letters
fox.ToUpper() converted to uppercase
fox.Trim () removes the before and after Spaces
fox.Trim (trimChars) deletes other characters
fox.TrimStart () removes the preceding space
fox.TrimEnd () delete the space after
fox. PadLeft(10) adds a space on the left to bring the string up to a certain length.
fox. PadRight(10) adds the right space to bring the string up to a certain length.
fox.PadX (10,'-') adds other characters to the string to reach a certain length. X refers to: Left/Right
fox.Split (") breaks a string into an array

System. Text. Encoding. Default. GetByteCount (fox); Get the length of the string, 1 character is equal to 2 characters

// get the location code of Chinese characters
byte[] array = new byte[2];
array = System. Text. Encoding. Default. GetBytes (" b ");

int i1 = (short)(array[0] - '\0');
int i2 = (short)(array[1] - '\0');

//unicode code in decoding mode
array = System. Text. Encoding. Unicode. GetBytes (" b ");
i1 = (short)(array[0] - '\0');
i2 = (short)(array[1] - '\0');

//unicode is decoded into 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);

//default mode is decoded into Chinese characters
array[0] = (byte)196;
array[1] = (byte)207;
s = System.Text.Encoding.Default.GetString(array);

Related articles: