search a sub string : string find « string « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » string » string find 
15.19.1.search a sub string
#include <iostream>
#include <string>
using namespace std;

int main()
{
  int i;
  string s1 ="this is a test.";
  string s2;

  i = s1.find("is");
  if(i!=string::npos) {
    cout << "Match found at " << i << endl;
    cout << "Remaining string is:\n";
    s2.assign(s1, i, s1.size());
    cout << s2;
  }
  cout << "\n\n";


  return 0;
}
Match found at 2
Remaining string is:
is is a test.
15.19.string find
15.19.1.search a sub string
15.19.2.string.find(substring)
15.19.3.string.rfind(substring)
15.19.4.string.find_first_of( substring )
15.19.5.Find the first occurance
15.19.6.Find first out of
15.19.7.string.find_last_of(substring)
15.19.8.string.find_first_not_of( substring )
15.19.9.Find the first that's not in this set, starting from the end
15.19.10.Find the first of any of these chars starting from the end
15.19.11.Search from the beginning
15.19.12.Search from the end
15.19.13.Find the first of any of these chars
15.19.14.Find the first that's not in this set
15.19.15.find last occurrence of a character - equivalent of strrchr()
15.19.16.find first occurrence of a substring - equivalent of strstr()
15.19.17.find last occurrence of a substring - no C-string equivalent
15.19.18.find first occurrence of a character - equivalent of strchr()
15.19.19.Searching for the first occurrence of a substring in a string
15.19.20.Searching for the last occurrence of a substring in a string
15.19.21.Searching for the first occurrence of a letter in a string
15.19.22.Searching for the last occurrence of a letter in a string
15.19.23.Searching for the first occurrence of any character other than o, n, e, or space
15.19.24.Searching for the last occurrence of any character other than o, n, e, or space
15.19.25.Using find with reverse iteration
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.