find() function rfind() function

First, let's understand that find() finds the character or string you are looking for from front to back. rfind() finds the character or string you are looking for from back to front.

find()

s.find(‘a’)

It means to find the character 'a' from position 0, return the position, and return the maximum value of an unsigned integer if it is not found. Converting to a signed integer is -1.

s="acasf";
s.find('a');等于0

s.find(‘a’,1);

Look for 'a' starting at position 1. Ditto not found The
default is to start from zero.

s="acasf";
s.find('a',1);等于2

s.find(“ca”)

Returns the position of the first character matched.

s="acasf";
s.find("ca");等于1

s.find(“ca”,2)

Find from position 2:

s="acasf";
s.find("ca",2);转化成有符号的也就是-1

Similar to rfind()

rfind() searches from the back to the front. Others have been with find. The string found is also the position where the first character of the match is returned.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263332&siteId=291194637