[C #] clear spaces in a string

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.