strchr
在字符串中进行搜索的函数是strchr,它接受两个参数(Linux man手册中的描述)
SYNOPSIS
#include <string.h>
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
该函数在字符串中返回字符参数第一次出现的位置,成功就返回指向该位置的指针,未找到返回NULL
strstr
SYNOPSIS
#include <string.h>
char *strstr(const char *haystack, const char *needle);
用法和strchr相似
substr
在学习C++时候遇到的函数,没有在linux中man到
substr()函数的用法_但行好事,莫问前程-CSDN博客_s.substr
返回一个string,包含s中从pos开始的n个字符的拷贝。
s.substr(pos,n); //pos从此位置开始拷贝,拷贝n长度的字符串