Sunday 5 January 2014

How To Remove duplicate space within character - C#

Leave a Comment
This example show the method to remove duplicate space in data. You can use this method to remove duplicate space within the word.

public string removeDuplicateSpace(string data)
{
     string _temp = data;
     string reBuildData = "";
     bool space = false;
     foreach (char a in _temp)
     {
         if (a == ' ')
         {
             if (!space)
             {
                 space = true;
                 reBuildData += a;
             }                   
          }
          else
          {
             reBuildData += a;
             space = false;
          }
      }
      return reBuildData;
}

Input :

 Hello         World

Output :

Hello World 


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.