本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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() ) );
}
示例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 );
}