【字符串函数】

#iostream

isalpha(ch);  小写字母返回2 大写字母返回1 其他返回0
islower() || isupper()  返回 1 / 0
tolower 字母转小写, 非字母不操作
toupper 转大写


#cstring

b 复制到 a 后
strcat(a, b);

从 a 拷贝前len位到 b
strncpy(b, a, len)

字符数组比较
strncmp(a + i, b + j, n)	前n位
strcmpi(a, b)	忽略大小写

在 s字符数组中查找 l字符数组 返回匹配的首地址指针
string类 s.find()
char s[50]="GoldenGlobalView";
char l[50]="lob";
char *p = strstr(s,l);	|| strstr(s,"lob");
cout << p << endl;		/// "lobalView"
找不到 == NULL

以' '或'a'为界分割字符串
char *t = strtok(ch, " a");
while (t != NULL)
{		
	word.insert(t);
	t = strtok(NULL, " a");
}


#string

复制某一段
string a;
string b = a.substr(s, len);
s不写默认从头开始 len不写默认到结束

大小写 strcmp 例题

strstr strcpy 例题

strtok 例题

猜你喜欢

转载自blog.csdn.net/ummmmm/article/details/82468426