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


C++ STR::find方法代码示例

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


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

示例1: spoonerize

	/*
	 * Returns a string that Spoonerism has been performed on.
	 * A string is spoonerized by swapping the beginning of the first word in
	 * the string with the beginning of the second word.
	 * <param_name = "first_len"> : Represents the number of characters from
	 * the first word to swap.
	 * <param_name = "second_len"> : Represents the number of characters from
	 * the second word to swap.
	 * If the word frequency of the string, along with first_len and second_len
	 * exceed 2, then the original string is returned.
	 */
	STR spoonerize( STR str, const int &first_len, const int &second_len ) {
		if ( word_frequency( str ) > 2 ||
			( ( first_len < 1 || first_len > 2 ) || 
			( second_len < 1 || second_len > 2 ) ) ) 
			return str;
		
		std::stringstream ss;
		std::size_t space_pos = str.find( ' ' );

		if ( first_len == 1 && second_len == 1 ) {
			std::swap( str[0], str[( space_pos + 1 )] );
			return str;
		} else if ( first_len == 2 && second_len == 1 ) {
			ss << str[( space_pos + 1 )] << str.substr( 2, ( space_pos - 1 ) ) <<
				str.substr( 0, 2 ) << str.substr( ( space_pos + 2 ), ( str.size() - 1 ) );
		} else if ( first_len == 1 && second_len == 2 ) {
			ss << str.substr( ( space_pos + 1 ), 2 ) << str.substr( 1, space_pos ) <<
				str[0] << str.substr( ( space_pos + 3 ), ( str.size() - 1 ) );
		} else if ( first_len == 2 && second_len == 2 ) { 
			ss << str.substr( ( space_pos + 1 ), 2 ) << str.substr( 2, space_pos - 1 ) <<
				str.substr( 0, 2 ) << str.substr( ( space_pos + 3 ), ( str.size() - 1 ) );
		}

		str = ss.str();
		return str;
	}
开发者ID:c4po187,项目名称:libstrct,代码行数:37,代码来源:libstrct.hpp

示例2: distribute

	/*
	 * Returns a vector of strings from the specified string, which has
	 * been sliced at each position where the delimiter appears.
	 */
	std::vector<STR> distribute( STR str, CSTR_R delimiter ) {
		std::vector<STR> slices;
		std::size_t pos = 0;

		while ( ( pos = str.find( delimiter ) ) != STR::npos ) {
			slices.push_back( str.substr( 0, pos ) );
			str.erase( 0, ( pos + delimiter.length() ) );
		}

		return slices;
	}
开发者ID:c4po187,项目名称:libstrct,代码行数:15,代码来源:libstrct.hpp

示例3: ContainsOnlyCharsT

static bool ContainsOnlyCharsT(const STR& input, const STR& characters)
{
    for(typename STR::const_iterator iter=input.begin();
        iter!=input.end(); ++iter)
    {
        if(characters.find(*iter) == STR::npos)
        {
            return false;
        }
    }
    return true;
}
开发者ID:Strongc,项目名称:Chrome_Library,代码行数:12,代码来源:string_util.cpp

示例4: SplitStringUsingSubstrT

 static void SplitStringUsingSubstrT(const STR& str,
     const STR& s, std::vector<STR>* r)
 {
     typename STR::size_type begin_index = 0;
     while(true)
     {
         const typename STR::size_type end_index = str.find(s, begin_index);
         if(end_index == STR::npos)
         {
             const STR term = str.substr(begin_index);
             STR tmp;
             TrimWhitespace(term, TRIM_ALL, &tmp);
             r->push_back(tmp);
             return;
         }
         const STR term = str.substr(begin_index, end_index-begin_index);
         STR tmp;
         TrimWhitespace(term, TRIM_ALL, &tmp);
         r->push_back(tmp);
         begin_index = end_index + s.size();
     }
 }
开发者ID:abyvaltsev,项目名称:putty-nd3.x,代码行数:22,代码来源:string_split.cpp

示例5: slice_after

	/*
	 * Returns the portion of the string after the delimiter.
	 */
	STR slice_after( STR str, CSTR_R delimiter ) {
		std::size_t pos = str.find( delimiter );
		return str.substr( ( pos + delimiter.size() ) );
	}
开发者ID:c4po187,项目名称:libstrct,代码行数:7,代码来源:libstrct.hpp

示例6: slice_before

	/*
	 * Returns the portion of the string before the specified delimiter.
	 */
	STR slice_before( STR str, CSTR_R delimiter ) {
		std::size_t pos = str.find( delimiter );
		return str.substr( 0, pos );
	} 
开发者ID:c4po187,项目名称:libstrct,代码行数:7,代码来源:libstrct.hpp


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