C++获取字符串中的某个子串
string FindField(const char* buf, const char* start, const char *end ,size_t bufSize) { if(bufSize <=0 ){ bufSize = strlen(buf); } const char *msg_start = buf, *msg_end = buf + bufSize; size_t len = 0; if (start != NULL) { len = strlen(start); msg_start = strstr(buf, start); } if (msg_start == NULL) { return ""; } msg_start += len; if (end != NULL) { msg_end = strstr(msg_start, end); if (msg_end == NULL) { return ""; } } return string(msg_start, msg_end); }
来源:ZLmediakit
“fnsvvavfdtgwegrgwwwwwwwwwwwwwwwww_asasasas_a” 查找w_到 _a之间的字符串;也就是asasasas
用于字符串解析,文件名解析等