Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2086223
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: C/C++

2009-01-04 15:49:47

size_t rfind ( const string& str, size_t pos = npos ) const;
size_t rfind ( const char* s, size_t pos, size_t n ) const;
size_t rfind ( const char* s, size_t pos = npos ) const;
size_t rfind ( char c, size_t pos = npos ) const;

Find last occurrence of content in string

Searches the string for the content specified in either str, s or c, and returns the position of the last occurrence in the string.

When pos is specified, the search only includes characters between the beginning of the string and position pos, ignoring any possible occurrences after pos.

Parameters

str
to be searched for in the object. The entire content of str must be matched in some part of the string to be considered a match.
s
Array with a sequence of characters.
In the second member function version, the size of the content to be matched is only determined by parameter n.
In the third version, a null-terminated sequence is expected, and its end is determined by the first occurrence of a null character in it.
n
Length of sequence of characters to search for.
c
Individual character to be searched for.
pos
Position of the first character in the string to be taken into consideration for possible matches. The default value indicates that the entire string is searched.

Return Value

The position of the last occurrence in the string of the searched content.
If the content is not found, the member value is returned.

Example

// string::rfind
#include 
#include 
using namespace std;

int main ()
{
  string str ("The sixth sick sheik's sixth sheep's sick.");
  string key ("sixth");
  size_t found;

  found=str.rfind(key);
  if (found!=string::npos)
    str.replace (found,key.length(),"seventh");

  cout << str << endl;

  return 0;
}

Output:

The sixth sick sheik's seventh sheep's sick.

Basic template member declarations

( basic_string )
typedef typename Allocator::size_type size_type;
size_type rfind ( const basic_string& str, size_type pos = npos ) const;
size_type rfind ( const charT* s, size_type pos, size_type n ) const;
size_type rfind ( const charT* s, size_type pos = npos ) const;
size_type rfind ( charT c, size_type pos = npos ) const;

See also

Find content in string (public member function)
Find character in string from the end (public member function)
Find absence of character in string from the end (public member function)
Replace part of string (public member function)
Generate substring (public member function)
阅读(1564) | 评论(0) | 转发(0) |
0

上一篇:string

下一篇:string::rfind

给主人留下些什么吧!~~