Double mynumber = 321.4321;
String mystring = string. Format ("{0: 0. ##}", mynumber );
Console. writeline (mystring );
String operation
Only two decimal places are allowed.
Double d1 = 3.1415926;
String strd1 = d1.tostring ("F2 ");
If there are three digits, It is F3.
String STR = "123abc456 ";
Int I = 3;
1. Take the first I character of the string.
STR = Str. substring (0, I); // or str = Str. Remove (I, str. Length-I );
2 remove the first I character of the string:
STR = Str. Remove (0, I); // or str = Str. substring (I );
3. Start from the right side with I characters:
STR = Str. substring (Str. Length-I); // or str = Str. Remove (0, str. Length-I );
4. Remove the I characters from the right:
STR = Str. substring (0, str. Length-I); // or str = Str. Remove (Str. Length-I, I );
5. If "ABC" exists in the string, remove it.
Using system. Text. regularexpressions;
String STR = "123abc456 ";
String A = "ABC ";
RegEx r = new RegEx ();
Match m = R. Match (STR );
If (M. Success)
{
// Select either the green or purple part.
STR = Str. Replace (,"");
Response. Write (STR );
String str1, str2;
Str1 = Str. substring (0, M. Index );
Str2 = Str. substring (M. index + A. length, str. Length-a.Length-m.Index );
Response. Write (str1 + str2 );
}
6. If the string contains "ABC", replace it with "ABC"
STR = Str. Replace ("ABC", "ABC ");
Public String strrep (string oldstr)
{
String newstr = oldstr. Replace ("<", "& lt ;");
Newstr = newstr. Replace (">", "& gt ;");
Newstr = newstr. Replace ("\ r \ n", "<br> ");
Newstr = newstr. Replace ("", "& nbsp ;");
Return newstr;
}
String temp = arr [0];
String [] S = temp. Split ('.');
String S1 = s [0];
String S2 = s [1];