string::find_first_of, find_last_of

DongWook Lee·2024년 7월 19일

C++

목록 보기
12/18

find_first_of(str)

return 값: str의 문자중 가장먼저 발생하는 문자의 위치

	string longer("That is a funny hat.");
	string shorter("issue");
	size_t loc1 = longer.find_first_of(shorter);			// 5
	size_t loc2 = longer.find_first_of('s');				// 6
	size_t loc3 = longer.find_first_of("this");				// 1
	size_t loc4 = longer.find_first_of("paper hat", 0, 5);	// 2

그 외

rfind : 문자열에서 문자열을 뒤에서 부터 검색한다.
find_first_not_of : 전달된 문자들 중 첫 번째로 일치하지 않는 것의 위치를 찾는다.
find_last_of : 전달된 문자들 중 가장 마지막에 나타나는 문자의 위치를 찾는다.
find_last_not_of : 전달된 문자들 중 마지막으로 일치하지 않는 것의 위치를 찾는다.
strspn : 일치하지 않는 문자의 첫번째 위치를 찾는다.

	// longer.size() == 20
	size_t loc5 = longer.find_first_not_of("paper hat");	// 0
	size_t loc6 = longer.find_last_of("paper hat");			// 18
	size_t loc7 = longer.find_last_not_of("paper hat");		// 19
    
    
	size_t loc8 = strspn("happy day.", "hello");			// 1
    // const char* 만 가능

0개의 댓글