I don't know if I've clearly understood your problem, but if you want to normalize multiple whitespaces, replacing them with a single whitespace, you can try this code snippet:
Code:
String normalizeWhitespaces(String s)
{
StringBuffer res = new StringBuffer();
int prevIndex = 0;
int currIndex = -1;
int stringLength = s.length();
String searchString = " ";
while((currIndex = s.indexOf(searchString, currIndex + 1)) >= 0)
{
res.append(s.substring(prevIndex, currIndex + 1));
while(currIndex < stringLength && s.charAt(currIndex) == ' ')
{
currIndex++;
}
prevIndex = currIndex;
}
res.append(s.substring(prevIndex));
return res.toString();
}
Pit