C # operation string Summary
C # operation string Summary
String stringMessage = string. Empty;
StringMessage. ToLower () to lowercase letters
StringMessage. ToUpper () is converted into uppercase letters
StringMessage. Trim () removes leading and trailing Spaces
StringMessage. Trim (trimChars) delete other characters
StringMessage. TrimStart () space before deletion
StringMessage. TrimEnd () space after deletion
StringMessage. PadLeft (10) adds spaces on the left to extend the string length.
StringMessage. PadRight (10) adds spaces on the right to extend the string length.
StringMessage. PadX (10, '-') adds other characters to make the string reach a certain length. X indicates Left/Right.
String [] messages = stringMessage. Split ('') Splits a string into arrays based on a specific character
Here, the Split () method is commonly used, for example:
String testString = "aaa, bbb, ccc, ddd ";
String [] testMessages = testString. Split (',');
TestMessages [0] = "aaa ";
TestMessages [1] = "bbb ";
TestMessages [2] = "ccc ";
TestMessages [3] = "ddd ";
String SEARCH:
Use the Indexof () and LastIndexof () methods to determine the index of the substring and then intercept it.
We can also implement the IFormattable interface to define our own string format class.
Public class MyFormatClass: IFormattable
{
Public double x, y, z;
Public Vector (double dx, double dy, double dz)
{
X = dx;
Y = dy;
Z = dz;
}
Public string ToString (string format, IFormatProvider formatProvider)
{
If (format = null)
Return ToString ();
String formatUpper = format. ToUpper ();
Switch (formatUpper)
{
Case "N ":
Return "|" + Norm (). ToString () + "| ";
Case "VE ":
Return String. Format ("({0: E}, {1: E}, {2: E})", x, y, z );
Case "IJK ":
StringBuilder sb = new StringBuilder (x. ToString (), 30 );
Sb. Append ("I + ");
Sb. Append (y. ToString ());
Sb. Append ("j + ");
Sb. Append (z. ToString ());
Sb. Append ("k ");
Return sb. ToString ();
Default:
Return ToString ();
}
}
Public override string ToString ()
{
Return "(" + x + "," + y + "," + z + ")";
}
Public double Norm ()
{
Return x * x + y * y + z * z;
}
}
Use regular expressions to control several common Regular Expressions in string format:
Internet address expression: http: // ([/w-] +/.) + [/w-] + (/[/w -./? % & =] *)?
Email Address expression:/w + ([-+.] /w +) * @/w + ([-.] /w + )*/. /w + ([-.] /w + )*
Zip code:/d {6}
Phone number :(/(/d {3}/) |/d {3 }-)? /D {8}