设为首页 加入收藏

TOP

[C++STDLib基础]关于C++string字符串的操作――C++标准库头文件<string> (二)
2015-11-21 01:22:52 来源: 作者: 【 】 浏览:13
Tags:STDLib 基础 关于 string 字符串 操作 标准 文件 < string>
_not_of( const char *str, size_type index, size_type num );
2.在字符串中查找第一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始,最多查找num个字符。如果没找到就返回string::nops?
3.在字符串中查找第一个与ch不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops?
?
find_last_of()函数:?
1.在字符串中查找最后一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops?
?size_type find_last_of( const char *str, size_type index, size_type num );
2.在字符串中查找最后一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,最多搜索num个字符。如果没找到就返回string::nops?
3.在字符串中查找最后一个与ch匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops?
?
find_last_not_of()函数:?
1.在字符串中查找最后一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops?
?size_type find_last_not_of( const char *str, size_type index, size_type num );
2.在字符串中查找最后一个与str中的字符都不匹配的字符,返回它的位置。搜索从index开始,最多查找num个字符如果没找到就返回string::nops?
3.在字符串中查找最后一个与ch不匹配的字符,返回它的位置。搜索从index开始。如果没找到就返回string::nops?
?
size_type rfind( const basic_string &str, size_type index );
size_type rfind( const char *str, size_type index );
size_type rfind( const char *str, size_type index, size_type num );
size_type rfind( char ch, size_type index );
rfind()函数: (逆向查找)
1.返回最后一个与str中的某个字符匹配的字符,从index开始查找。如果没找到就返回string::npos?
2.返回最后一个与str中的某个字符匹配的字符,从index开始查找,最多查找num个字符。如果没找到就返回string::npos?
3.返回最后一个与ch匹配的字符,从index开始查找。如果没找到就返回string::npos?
*/?
void test3()?
{???
??? string str1( "Alpha Beta Gamma Delta" );?
??? unsigned int loc = str1.find( "Omega", 0 );?
??? if( loc != string::npos )?
??????? cout << "Found Omega at " << loc << endl;?
??? else?
??????? cout << "Didn't find Omega" << endl;?
?
/*? 例如,在下列代码中第一次调用rfind()返回string::npos,因为目标词语不在开始的8个字符中。然而,第二次调用返回9,因为目标词语在开始的20个字符之中。 */?
??? int loc2;?
??? string s = "My cat's breath smells like cat food.";?
??? loc2 = s.rfind( "breath", 8 );?
??? cout << "The word breath is at index " << loc2 << endl;//-1??
??? loc2 = s.rfind( "breath", 20 );?
??? cout << "The word breath is at index " << loc2 << endl;//9??
}???
//插入(insert),替换(replace)???
/*
iterator insert( iterator i, const char &ch );
basic_string &insert( size_type index, const basic_string &str );
basic_string &insert( size_type index, const char *str );
basic_string &insert( size_type index1, const basic_string &str, size_type index2, size_type num );
basic_string &insert( size_type index, const char *str, size_type num );
basic_string &insert( size_type index, size_type num, char ch );
void insert( iterator i, size_type num, const char &ch );
void insert( iterator i, iterator start, iterator end );
insert()函数的功能非常多:?
1.在迭代器i表示的位置前面插入一个字符ch,?
2.在字符串的位置index插入字符串str,?
3.在字符串的位置index插入字符串str的子串(从index2开始,长num个字符),?
4.在字符串的位置index插入字符串str的num个字符,?
5.在字符串的位置index插入num个字符ch的拷贝,?
6.在迭代器i表示的位置前面插入num个字符ch的拷贝,?
7.在迭代器i表示的位置前面插入一段字符,从start开始,以end结束.?
?
basic_string &replace( size_type index, size_type num, const basic_string &str );
basic_string &replace( size_type index1, size_type num1, const basic_string &str, size_type index2,
size_type num2 );
basic_string &replace( size_type index, size_type num, const char *str );
basic_string &replace( size_type index, size_type num1, const char *str, size_type num2 );
basic_string &replace( size_type index, size_type num1, size_type num2, char ch );
basic_string &replace( iterator start, iterator end, const basic_string &str );
basic_string &replace( iterator start, iterator end, const char *str );
basic_string &replace( iterator start, iterator end, const char *str, size_type num );
basic_string &replace( iterator start, iterator end, size_type num, char ch );
replace()函数:?
1.用str中的num个字符替换本字符串中的字符,从index开始?
2.用str中的num2个字符(从index2开
首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇对A*算法的路径进行优化 下一篇※编程随笔※=>☆编程基础☆=&..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: