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


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

本文整理汇总了C++中std::basic_string::find_last_not_of方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::find_last_not_of方法的具体用法?C++ basic_string::find_last_not_of怎么用?C++ basic_string::find_last_not_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::basic_string的用法示例。


在下文中一共展示了basic_string::find_last_not_of方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TrimRight

void IO::TrimRight(std::basic_string<charType> & str, const char* chars2remove)
{
	if (!str.empty()) {  	//trim the characters in chars2remove from the right
		std::string::size_type pos = 0;
		if (chars2remove != NULL) {
			pos = str.find_last_not_of(chars2remove);

			if (pos != std::string::npos)
				str.erase(pos+1);
			else
				str.erase( str.begin() , str.end() ); // make empty
		}
		else {       		//trim space
			pos = std::string::npos;
			for (int i = str.size()-1; i >= 0; --i) {
				if (!isspace(str[i])) {
					pos = i;
					break;
				}
			}
			if (pos != std::string::npos) {
				if (pos+1 != str.size())
					str.resize(pos+1);
			}
			else {
				str.clear();
			}
		}
	}
}
开发者ID:AIBluefisher,项目名称:GraphCluster,代码行数:30,代码来源:io_utils.cpp

示例2: rstrip

 static inline std::basic_string<_CharT, _Traits, _Alloc> rstrip(
     const std::basic_string<_CharT, _Traits, _Alloc> &a,
     const strip_t stripchars) {
   typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
   typename str_t::size_type p = a.find_last_not_of(stripchars);
   if (p == str_t::npos) return "";
   return a.substr(0, p + 1);
 }
开发者ID:DarkOfTheMoon,项目名称:Carve,代码行数:8,代码来源:stringfuncs.hpp

示例3: trim

	template<typename char_t> std::basic_string<char_t> trim(const std::basic_string<char_t>& what)
	{
		if ( what.empty() ) return what;

		const char_t whitespace[3] = { char_t(' '), char_t('\t'), 0 };
		size_t left = what.find_first_not_of(whitespace);
		size_t right = what.find_last_not_of(whitespace);

		if ( left == std::basic_string<char_t>::npos )
		{
			return std::basic_string<char_t>();
		}
		else
		{
			return what.substr(left, right-left+1);
		}
	}
开发者ID:basmith,项目名称:BearLibTerminal,代码行数:17,代码来源:Utility.hpp


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