[Solved] how to remove a substring of unknown length from a string – C++ [closed]

Use rfind to get the location of the last slash then substr to return the right side of the string. Since substr‘s second argument defaults to “the end of the string” you only need to provide the beginning position: #include <string> std::string GetURLFilePath(const std::string& url) { auto last_slash_location = url.rfind(“https://stackoverflow.com/”); if(last_slash_location == std::string::npos || last_slash_location … Read more