How To Remove duplicate space within character - C#
This example show the method to remove duplicate space in data. You can use this method to remove duplicate space within the word.
By Mohd Zulkamal
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 =)
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 WorldOutput :
Hello WorldBy Mohd Zulkamal
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 =)