假设我有以下看起来像文件路径的字符串:
char *filepath = "this/is/my/path/to/file.jpg";
我可以strrchr()用来提取file.jpg如下:
char *filename = strrchr(filepath, '/') + 1;
现在我需要提取并存储字符串的其余部分this/is/my/path/to。我如何以最有效的方式做到这一点?请注意,我想避免使用strtok()orregex或大的迭代循环。
如果:
我可以将相同的子字符串提取技术应用于strchr()提取子字符串的位置this,strchr(filepath, '/')现在我需要提取其余的子字符串is/my/path/to/file.jpg