在我的 C++ 程序中,我有字符串
string s = "/usr/file.gz";
这里,如何制作脚本来检查 .gz
扩展名(无论文件名是什么)并将其拆分为 "/usr/file"
?
最佳答案
您可以使用 erase用于删除符号:
str.erase(start_position_to_erase, number_of_symbols);
您可以使用 find找到起始位置:
start_position_to_erase = str.find("smth-to-delete");
关于c++ - 如何从字符串中删除特定的子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532384/