How to find substring from string?
In C, use the strstr()
standard library function:
const char *str = "/user/desktop/abc/post/";
const int exists = strstr(str, "/abc/") != NULL;
Take care to not accidentally find a too-short substring (this is what the starting and ending slashes are for).
Use std::string
and find
.
std::string str = "/user/desktop/abc/post/";
bool exists = str.find("/abc/") != std::string::npos;