本文整理汇总了C++中std::string::find_last_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ string::find_last_not_of方法的具体用法?C++ string::find_last_not_of怎么用?C++ string::find_last_not_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::find_last_not_of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trim
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);
}
示例2: trim
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());
}
示例3:
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 "";
}
示例4: trimString
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);
}
示例5: trim
/***************************************************************//**
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);
}
示例6: trim
// 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);
}
}
示例7: trim
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);
}
示例8: Trim
// 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);
}
示例9: trim
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());
}
}
示例10: trim
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;
}
示例11: Trim
// --------------------------------------------------------------------------
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 );
}
示例12: Trim
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;
}
示例13: TrimSpaces
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 );
}
示例14: trim
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);
}
示例15: StringTrimInPlace
/// @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());
}
}