QCString QCString::simplifyWhiteSpace () const Returns a new string that has white space removed from the start and the end, plus any sequence of internal white space replaced with a single space (ASCII 32).White space means the decimal ASCII codes 9, 10, 11, 12, 13 and 32. QCString s = " lots\t of\nwhite space "; QCString t = s.simplifyWhiteSpace(); // t == "lots of white space"
QT库里有这样的函数.QCString QCString::simplifyWhiteSpace() const { if ( isEmpty() ) // nothing to do return copy(); QCString result( size() ); char *from = data(); char *to = result.data(); char *first = to; while ( TRUE ) { while ( *from && isspace((uchar) *from) ) from++; while ( *from && !isspace((uchar)*from) ) *to++ = *from++; if ( *from ) *to++ = 0x20; // ' ' else break; } if ( to > first && *(to-1) == 0x20 ) to--; *to = '\0'; result.resize( (int)((long)to - (long)result.data()) + 1 ); return result; }http://service-spi.web.cern.ch/service-spi/external/doxygen/1.3-rc2/rh73_gcc32/qtools/qcstring.cpp
Returns a new string that has white space removed from the start and the end, plus any sequence of internal white space replaced with a single space (ASCII 32).White space means the decimal ASCII codes 9, 10, 11, 12, 13 and 32. QCString s = " lots\t of\nwhite space ";
QCString t = s.simplifyWhiteSpace(); // t == "lots of white space"
QT库里有这样的函数.QCString QCString::simplifyWhiteSpace() const
{
if ( isEmpty() ) // nothing to do
return copy();
QCString result( size() );
char *from = data();
char *to = result.data();
char *first = to;
while ( TRUE ) {
while ( *from && isspace((uchar) *from) )
from++;
while ( *from && !isspace((uchar)*from) )
*to++ = *from++;
if ( *from )
*to++ = 0x20; // ' '
else
break;
}
if ( to > first && *(to-1) == 0x20 )
to--;
*to = '\0';
result.resize( (int)((long)to - (long)result.data()) + 1 );
return result;
}http://service-spi.web.cern.ch/service-spi/external/doxygen/1.3-rc2/rh73_gcc32/qtools/qcstring.cpp
{
zh=str.GetAt(s);
if(zh=" ")
{
str.Delete(s,2);
}
这明显是错的吧.数组的下标是从0开始的
for(int s=0;s<str.GetLength();s=+2)
还有.为什么要加2呢?实现方法可以参考我给你的那个函数.
if(zh=" ") //TCHAR不能和char*比较
而且前面不是说了吗,直接用
str.Remove(' ');
就能删除空格了。
另外,楼上说的“得到行串,然后遇到空格和'\r' '\n'就删”也不好。