且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何找到字符串的子串?

更新时间:2023-02-06 17:05:13

在C,使用 的strstr() 标准库函数:

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).