static std::string trim(const std::string &trimstring, const std::string &spaces = " \t") { const size_t startpos = trimstring.find_first_not_of(spaces); if( startpos == std::string::npos ) return ""; const size_t endpos = trimstring.find_last_not_of(spaces); const size_t total = endpos - startpos + 1; return trimstring.substr(startpos, total); }
void trim(std::string &str, char ch) { std::string::size_type pos = str.find_last_not_of(ch); if(pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(ch); if(pos != std::string::npos) str.erase(0, pos); } else str.erase(str.begin(), str.end()); }
std::string String::rtrim(const std::string& s) { size_t last = 0; last = s.find_last_not_of(BLANK_CHARACTERS); if (last != std::string::npos) return s.substr(0, last + 1); // If we get here the string only has blanks. return ""; }
void MiscUtil::trimString( std::string &string ){ size_t begin = string.find_first_not_of(" \t\r\n"); if (begin == std::string::npos){ // Empty Line string = ""; return; } size_t end = string.find_last_not_of(" \t\r\n"); size_t length = end - begin + 1; string = string.substr(begin, length); }
/***************************************************************//** Remove leading and trailing white spaces in a string @param str String to modify *******************************************************************/ void ReadConfig::trim(std::string & str) { using namespace std; // Search for first non-white character string::size_type first = str.find_first_not_of(" \t\n", 0); // Search for last non-white character string::size_type last = str.find_last_not_of(" \t\n"); // Trim if(first == string::npos && last == string::npos) str.clear(); else str = str.substr(first, last-first+1); }
// Remove whitespace around a string std::string trim(const std::string &in) { size_t first = in.find_first_not_of(" "); size_t last = in.find_last_not_of(" "); if (first == std::string::npos || last == std::string::npos) { return in; } else { return in.substr(first, last - first + 1); } }
std::string trim(const std::string &str) { const char *whitespace = "\t \n\r"; size_t start = str.find_first_not_of(whitespace); size_t end = str.find_last_not_of(whitespace); // no non-whitespace characters, return the empty string if(start == std::string::npos) return ""; // searching from the start found something, so searching from the end must have too. return str.substr(start, end - start + 1); }
std::string oskar_settings_utility_string_trim(const std::string& s, const std::string& whitespace) { // Find the first index that does not match whitespace. size_t i0 = s.find_first_not_of(whitespace); if (i0 == std::string::npos) return ""; // Find the last index that does not match whitespace. size_t i1 = s.find_last_not_of(whitespace); // Find the string with whitespace subtracted from each end. return s.substr(i0, i1 - i0 + 1); }
// Trim - trim white space off the start and end of the string // str - string to trim // NOTE: if the entire string is empty, then the string will be set to an empty string void Trim(std::string& str) { auto found = str.find_first_not_of(" \t"); if (found == npos) { str.erase(0); return; } str.erase(0, found); found = str.find_last_not_of(" \t"); if (found != npos) str.erase(found + 1); }
void trim(std::string& str) { std::string whiteSpaces = " \r\n\t"; std::string::size_type pos = str.find_last_not_of(whiteSpaces); if(pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(whiteSpaces); if(pos != std::string::npos){ str.erase(0, pos); } } else { str.erase(str.begin(), str.end()); } }
string trim(const std::string & str){ string s; size_t startpos = str.find_first_not_of(" \t"); size_t endpos = str.find_last_not_of(" \t"); // if all spaces or empty return an empty string if ((string::npos == startpos) || (string::npos == endpos)){ return ""; } else { return str.substr(startpos, endpos-startpos+1); } return str; }
// -------------------------------------------------------------------------- std::string Trim(const std::string& str, const std::string& trim) { if ( str.empty() ) return ""; std::string::size_type begin = str.find_first_not_of( trim ); if ( begin == std::string::npos ) return ""; std::string::size_type end = str.find_last_not_of( trim ); return std::string( str, begin, end - begin + 1 ); }
std::string Trim(std::string str) { size_t End = str.find_last_not_of(" \t"); if (std::string::npos != End){ str = str.substr(0, End + 1); } size_t Start = str.find_first_not_of(" \t"); if (std::string::npos != Start){ str = str.substr(0, Start); } return str; }
static void TrimSpaces( std::string &str ) { // http://sarathc.wordpress.com/2007/01/31/how-to-trim-leading-or-trailing-spaces-of-string-in-c/ size_t startpos = str.find_first_not_of(" \t"); // Find the first character position after excluding leading blank spaces size_t endpos = str.find_last_not_of(" \t"); // Find the first character position from reverse af // if all spaces or empty return an empty string if(( std::string::npos == startpos ) || ( std::string::npos == endpos)) { str = ""; } else str = str.substr( startpos, endpos-startpos+1 ); }
std::string trim(const std::string& str, const std::string& whitespace) { const auto strBegin = str.find_first_not_of(whitespace); if (strBegin == std::string::npos) { return ""; // no content } const auto strEnd = str.find_last_not_of(whitespace); const auto strRange = strEnd - strBegin + 1; return str.substr(strBegin, strRange); }
/// @see http://www.codeproject.com/KB/stl/stdstringtrim.aspx void StringTrimInPlace(std::string& str, const std::string& ws) { std::string::size_type pos = str.find_last_not_of(ws); if (pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(ws); if (pos != std::string::npos) { str.erase(0, pos); } } else { str.erase(str.begin(), str.end()); } }
void StrTrimRight(std::string& a_str) { std::string::size_type l_pos = a_str.find_last_not_of(" \t\r\n"); if(l_pos != std::string::npos) { a_str.erase(l_pos + 1); } else { a_str.clear(); } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // Function name : CFilePref::Trim // Description : Removes any leading and trailing values in strRemove from strToTrim // Return type : void // Argument : std::string & strToTrim // Argument : const std::string & strRemove // void CFilePref::Trim( std::string & strToTrim, const std::string & strRemove /*= " "*/ ) { std::string::size_type nBegin = strToTrim.find_first_not_of(strRemove); std::string::size_type nEnd = strToTrim.find_last_not_of(strRemove); if(std::string::npos == nBegin) { strToTrim.erase(); } else { nEnd = std::string::npos == nEnd ? 0 : nEnd; strToTrim = strToTrim.substr( nBegin, nEnd - nBegin + 1); } }
void NamedColumnsParser::checkPrune(std::string& str, bool prune) const { if (!prune) { return; } std::string::size_type idx = str.find_first_not_of(" "); if (idx != std::string::npos) { str = str.substr(idx); } idx = str.find_last_not_of(" "); if (idx != std::string::npos && idx != str.length() - 1) { str = str.substr(0, idx + 1); } }
/////////////////////////////////////////////////////////////////// // liefert laenge der laengsten wiederholung von <c> in <str> /////////////////////////////////////////////////////////////////// int Util_String::maxSubseq( const std::string &str, const char c) { int m=0, act=0; std::string::size_type i=str.find_first_not_of(c); for(;i<str.find_last_not_of(c);i++) { // std::cerr <<i <<" = " <<str[i] ; if (str[i]==c) act++; else act=0; if (act > m) m = act; // std::cerr <<" act = " <<act <<" max = " << m <<"\n"; } return m; }
std::string trim(const std::string& input) { size_t size = input.size(); if (size == 0 || (!isBlankChar(input[0]) && !isBlankChar(input[size-1]) ) ) { return input; } size_t start = input.find_first_not_of(" \t\n\r"); size_t end = input.find_last_not_of(" \t\n\r"); if (start >= end) { return ""; } return input.substr(start, end+1); }
std::string trim(std::string const& str) { std::size_t first = str.find_first_not_of(' '); // If there is no non-whitespace character, both first and last will be std::string::npos (-1) // There is no point in checking both, since if either doesn't work, the // other won't work, either. if (first == std::string::npos) return ""; std::size_t last = str.find_last_not_of(' '); return str.substr(first, last - first + 1); }
void string_trim(std::string& str) { size_t pos = str.find_first_not_of(" \f\n\r\t\v",0); if(pos != std::string::npos) { str.erase(0, pos); } pos = str.find_last_not_of(" \f\n\r\t\v", str.length()); if(pos != std::string::npos && pos < str.length()-1) { str.erase(pos+1); } }
std::string ConfigFile::trim(std::string str) { int i, j; i = str.find_first_not_of(" "); if (i==-1) return ""; // all chars are space if (i>0) str = str.substr(i); // cut top spaces j = str.find_last_not_of(" "); if (j>0) str = str.substr(0, j+1); // cut bottom spaces return str; }
//============================================================================ // FUNCTION : SPELLutils::trim //============================================================================ void SPELLutils::trim( std::string& str ) { std::string::size_type pos = str.find_last_not_of(' '); if(pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(' '); if(pos != std::string::npos) str.erase(0, pos); } else { str.erase(str.begin(), str.end()); } }
std::string osgDB::trimEnclosingSpaces(const std::string& str) { if (str.empty()) return str; const std::string whitespaces(" \t\f\v\n\r"); std::string::size_type start = str.find_first_not_of(whitespaces); if (start==std::string::npos) return std::string(); std::string::size_type end = str.find_last_not_of(whitespaces); if (end==std::string::npos) return std::string(); return std::string(str, start, (end-start)+1); }
void trim(std::string& str) { size_t s = str.find_first_not_of(" \t\r\n"); if (s != std::string::npos) { str.erase(0, s); } else { str.clear(); return; } size_t e = str.find_last_not_of(" \t\r\n"); if (e != std::string::npos) str.erase(e + 1); }
static std::string trim(std::string s) { size_t begin_str = s.find_first_not_of(" \t\n\r"); if(begin_str != std::string::npos) { size_t last = s.find_last_not_of(" \t\n\r"); if(last >= begin_str) { std::string trimmed = s.substr(begin_str, last - begin_str + 1); return trimmed; } else { return ""; } } else { return ""; } }
std::string trim(std::string &str, char ch) { if(str.length() == 0){ return str; } int sPos = str.find_first_not_of(ch); int ePos = str.find_last_not_of(ch); if(sPos == -1){ return str.erase(); } return str.substr(sPos, ePos - sPos + 1); }
std::string RemoveWhiteSpace( std::string line ) { // std::string line( _line ); size_t position = line.find_first_not_of(" \t"); if( position != 0 ) line.erase( 0, position ); position = line.find_last_not_of(" \t"); if( position != line.size() - 1 ) line.erase( position+1 ); return line; }