Three methods and efficiency for clearing stringbuilder We know that stringbuilder is used for frequent String concatenation. the append method is much more efficient than the string + = method, but sometimes you do not know how to clear stringbuilder because it does not have the clear or empty method. So what method is used? I searched the internet for three methods. 1. Remove example: stringbuilder val = new stringbuilder (); Val. append (".... "); Val. remove (0, Val. length); // clear 2. Replace stringbuilder val = new stringbuilder (); Val. append (".... "); Val. replace (Val. tostring (), ""); // clear 3. Length stringbuilder val = new stringbuilder (); Val. append (".... "); Val. length = 0; // empty the efficiency of the three methods is simply tested, and the average value of the three methods is tested: datetime dt = datetime. now; const int testnum= 1000000; stringbuilde R strbuilder = new stringbuilder (); For (INT I = 0; I <testnum; I ++) {strbuilder. append ("test"); strbuilder. remove (0, strbuilder. length);} console. writeline ("rsemove:" + (datetime. now-Dt ). ticks); first, time used: 366687; second, time used: 1186734; third, time used: 180010, visible, or length used, which is more efficient. This test is my simple test. If you have different opinions, please leave a message to study and discuss it together!