|
String SearchingYou can use the find function to locate a character or substring in a string:
The first call to find returns the index of the first occurrence of t in the string. Since t is the tenth character in the string, its index is 9. To only search part of a string, supply a start and end index when calling find:
The two additional parameters to find specify the start and end indexes of the search. In this example, find starts its search at index 16, which is the 17th character of the string. It stops the search at index 22.
The rfind function is similar to find, except that it returns the index of the last occurrence of a character or substring in a string:
|