字符串截取
string str = "012345";
//从第0位开始截取3个
string str1 = str.substr(0,3) //012
//获取字符串的最后一位
string str2 = str.substr(str.length()-1,1) //5
https://www.cnblogs.com/komean/p/11109555.html
s.find(s1)
https://blog.youkuaiyun.com/sr_19930829/article/details/21476287
查找最后一次出现字符串xxx的位置
#include <iostream>
using namespace std;
int main()
{
string str = "//bear.jpg";
int pos= str.find_last_of("/");
cout<<pos<<endl;
}
查找字符串xxx最后一次出现的位置 并截取此位置到字符串末尾
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{
char fp[500] = "/host/HY/linux/GTK/HTYPaint/bear.jpg";
string ptr = strrchr(fp, '/');
cout<<ptr<<endl;
}
查找字符串xxx第一次出现的位置 并截取此位置到字符串末尾
strchr
把字符串以一个字符 一个字符串 多个字符来分割
https://blog.youkuaiyun.com/zhangxiong1985/article/details/84503341
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
//以,来分割字符串 分割后,消失1,2,.3->1 2 .3
std::vector<std::string> shape_vec;
boost::split(shape_vec,op_stru0.inputs_shape,boost::is_any_of(","),boost::token_compress_on);
//以,或.来分割字符串 分割后,.消失1,2,.3->1 2 3
std::vector<std::string> shape_vec;
boost::split(shape_vec,op_stru0.inputs_shape,boost::is_any_of(",."),boost::token_compress_on);
//以abc作为整体来分割efadabcr->efad r
#include <boost/regex.hpp>
#include <boost/algorithm/string/regex.hpp>
std::string text = "efadabcr";
std::vector<std::string> results;
boost::split_regex(results, text, boost::regex("abc"));
format