How to remove whitespaces if it is more than 2. What i want to say is -
1. If there is one whitespace, its OK.
2. If there is two whitespace, its OK.
3. BUT, if there is more than two whitespace than replace them with only two whitespaces.
String may be like this :- (it may contain any character)
DuntaviDilaniyd.dilaniy@woridnitattnit 15 jim alixandir id PALESTINE TX
48568 2470325837 US FEMALESunday, April 09, 1939 162 170 A+ • Duntavia
Delaney Jon Muller Sherman TX 84321 US 9974766226 NO NO YES
NO NO Yt i7-Uri-11616 Sunday, April 09, 1939 $200.00 ' Duntavia Delaney
Sherrie Minter BaX OlaCp 9719 Sunday, April 09, 1939 FEMALEVisa CLONAZAPAM 10
MG 60 $2.85 5171.00 $20.00 $191.00 Not Available
public static string ConvertWhitespaceToSpaces(string value)
{
char[] arr = value.ToCharArray();
for (int i = 0; i < arr.Length; i++)
{
switch (arr[i])
{
case '\t':
case '\r':
case '\n':
case ' ':
{
arr[i] = ' ';
break;
}
}
}
return new string(arr);
}
I did this but it doesn't work as per my need.
I did this too :--
List<string> splitStrings = str.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
string[] words = splitStrings.ToArray();