Key code:
/// <Summary> /// Clear spaces in the string /// </Summary> /// <Param name = "str"> string to be processed </param> /// <Returns> processed string </returns> Public Static String Effectblanks ( This String Str ){ Int _ Length = Str. length;If (_ Length> 0) {stringbuilder _ builder = New Stringbuilder (_ length ); For ( Int I = 0; I <Str. length; I ++ ){ Char _ C = STR [I]; // Switch (_ C) //{ // Case '\ R ': // Case '\ N ': // Case '\ t ': // Case '': // Continue; // Default: // _ Builder. append (_ C ); // Break; //} If (! Char . Iswhitespace (_ C) _ builder. append (_ C );} Return _ Builder. tostring ();} Return STR ;}
Test code:
[testmethod ()] Public void effectblkstest () { string STR = @ "20140901 11 22 33" ; // todo: initialize to an appropriate value string expected = "20140901112233" ; // todo: initialize to an appropriate value string actual = stringtoolv2.20.tblks (STR); assert. areequal (expected, actual) ;}
Test results:
Hope this is helpful!
[C #] clear spaces in a string