All pastes #1396818 Raw Edit

trim whitespace c++

public cpp v1 · immutable
#1396818 ·published 2009-04-19 22:24 UTC
rendered paste body
std::string trim(std::string& str){	std::string _buffer;	uint len = str.length();	uint i;	int spaces = 0;	for(i = 0; i < len; i++)	{		char c = str.at(i);		// ueberpruefe ob eines der character ein whitespace char ist		if(c != 0x09 && c != 0x0a && c != 0x0c && c != 0x0d) 		{			if( i == 0 && c == 0x20) 			{				++spaces;			}			if(c == 0x20 && spaces < 1)			{				++spaces;				_buffer.push_back(c);			} 						else if(c != 0x20)			{				spaces = 0;				_buffer.push_back(c);			}					}	}	return _buffer;}