比如:字符串 “cu_f”,现在只要”cu”,也就是去掉”_f”
std::string str1=”cu_f”;
int pos=0;
pos=str1.find(“_f”); ///获取”_f”出现的位置
if(-1 == pos) ///pos=-1说明没有找到 “_f”
{
return;
}
std::string str2=str1.substr(0,pos);
str2即为所要的”cu”字符串
C++ 查找字符串中的子串,截取子串前的所有字符
最新推荐文章于 2024-06-20 17:14:51 发布