TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ String rfind() function

C++ String rfind() function tutorial for beginners and professionals with examples on constructor, if-else, switch, break, continue, comments, arrays, object and class, exception, static, structs, inheritance, aggregation etc.

<< Back to CPP

C++ String rfind()

This function is used to find the string for the last occurrence of the sequence specified by its arguments.

Syntax

Consider a string 'str' and key string 's'. Syntax would be:

str.rfind(s);
str.rfind(s,pos);
str.rfind(s,pos,n);
str.rfind(ch);

Parameter

str : str is a string object which is used in searching.

pos : It defines the position of the last character at which to start searching.

n : Number of characters to be considered in searching

ch : Character value to be searched for.

Example 1

Let's see this simple example.

#include<iostream>
using namespace std;
int main()
{
	string str="This is an object oriented programming language";
	string key="language";
	int i=str.rfind(key);
	cout<<i;
	return 0;
}

Output:

39

Example 2

Let's see an another simple example by passing character value.

#include<iostream>
using namespace std;
int main()
{
	string str="Computer Science";
            int i=str.rfind('e');
	cout<<i;
	return 0;
}

Output:

15

Example 3

Let's see this example when position pos is mentioned in a parameter.

#include<iostream>
using namespace std;
int main()
{     
 string str="Digital electronics is a B.tech subject";
int i=str.rfind("is",21);
cout<<i;
return 0;
}

Output:

20

Example 4

Let's see this example when number of characters to match is specified by its arguments.

#include<iostream>
using namespace std;
int main()
{
	string str="Java is an object oriented programming language";
            int i=str.rfind("programming",40,7);
	cout<<i;
	return 0;
}

Output:

27

Next TopicC++ Strings




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf