当前位置: 首页>>代码示例>>C++>>正文


C++ string::find_last_not_of方法代码示例

本文整理汇总了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);
            }
开发者ID:orgcandman,项目名称:cxx-useful,代码行数:13,代码来源:strings.hpp

示例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());
}
开发者ID:norihiro-w,项目名称:ogs,代码行数:13,代码来源:StringTools.cpp

示例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 "";
    }
开发者ID:Aero348,项目名称:dune,代码行数:13,代码来源:String.cpp

示例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);
}
开发者ID:MA5YK,项目名称:AmibrokerFeeder,代码行数:13,代码来源:misc_util.cpp

示例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);
}
开发者ID:Radioguy00,项目名称:FakeMsg,代码行数:20,代码来源:read_config.cpp

示例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);
	}
}
开发者ID:Bindernews,项目名称:HeadlessQuickNes,代码行数:14,代码来源:options.cpp

示例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);
}
开发者ID:cgmb,项目名称:renderdoc,代码行数:13,代码来源:string_utils.cpp

示例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);
}
开发者ID:shyamalschandra,项目名称:CNTK,代码行数:16,代码来源:DataReader.cpp

示例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());
    }    
}
开发者ID:awarematics,项目名称:SECONDO,代码行数:13,代码来源:StringUtils.cpp

示例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;
}
开发者ID:MortimerBlater,项目名称:paintown,代码行数:13,代码来源:serialize.cpp

示例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 );
}
开发者ID:dfleury2,项目名称:Nedit,代码行数:14,代码来源:utils.cpp

示例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;
}
开发者ID:Abscission,项目名称:platform-game,代码行数:13,代码来源:Utility.cpp

示例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 );  
}  
开发者ID:AdiBoy,项目名称:mtasa-blue,代码行数:13,代码来源:mantisbot.cpp

示例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);
}
开发者ID:atlasclash,项目名称:clash-stats,代码行数:13,代码来源:StringHelpers.cpp

示例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());
	}
}
开发者ID:AMDmi3,项目名称:spring,代码行数:14,代码来源:Util.cpp


注:本文中的std::string::find_last_not_of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。