Hi, I read on another thread like this, that the easiest way to remove whitespace in C#, would probably be
Regex.Replace(input, @"\s", "");
But I'm really confused with how Regex Works, Is there a way you could modify it so ..it only replaces the whitespace if there is more than one?
Like if you had a string like this " \r\n A \r\n String \r\n\r\nLike\r\n\r\nThis" turn it into "A String Like This"
I made something that does that in regular C (not very optimized) but have no ideas how to do it in C#, because the String functions arn't as nice as the STD ones in C..but anyway
here is the code in C of how I did it..Let me know if you have any pointers on how to do it in C#..Thanks
string WHITESPACE = " \r\n\t";
int index = 0;
int wsf, wsb;
//trim the front and back first
wsf = Target.find_first_not_of(WHITESPACE);
if (wsf != string::npos)
{
wsb = Target.find_last_not_of(WHITESPACE);
if (wsb != string::npos)
{
Target = Target.sbustr(wsf, wsb - wsf +1);
}
}
//Get space inbetween words
while (Target.find_first_of(WHITESPACE, index) != string::npos)
{
index = Target.find_first_of(WHITESPACE, index);
int b = Target.find_first_not_of(WHITESPACE, index);
if((b -index) > 1 )
{
Target = Target.erase(index, (b-index -1));
index++;
}
//Target now is a good string