Linux网络编程中常用的字符串相关的函数

1、strpbrk函数

#include<string.h>
char* strpbrk(char* s1, char* s2);

strpbrk()从第一个字符指针指向的位置 向后检查每个字符,直到遇到\0(不检查\0),如果检查到的某个字符在s2指向的字符串中,那么返回他的地址,并停止检查。

如果s1 、s2没有相同字符,返回NULL。

注:传入strpbrk函数的两个变量可以是一个指针,也可以是一个字符串。

2、strcasecmp函数

#include<string.h>
int strcasecmp(const char* s1, const char* s2);

忽略大小写地按字典序比较s1 、s2两个字符串。
返回值类型是int,如果s1 、s2相等,则返回0,如果是s1大,那么返回s1中第一个大于s2的字符的int型 正数ASCII 码,反之,返回s2中第一个大于s1的字符的int型 负数ASCII 码。

实例:

#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

int main()
{
   
	char a[30] = {
   "asdasd"};
	char b[30] = {
   "asdasdasda"};
	char* p;
	p = b;
	auto x = strcasecmp(p,a);
	printf("%d\n",x);
}

输出:

97
#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

int main()
{
   
	char a[30] = {
   "asdasd"};
	char b[30] = {
   "asdasd"};
	char* p;
	p = b;
	auto x = strcasecmp(p,a);
	printf("%d\n", x);
}

输出:

0
#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

int main()
{
   
	char a[30] = {
   "asdasd"};
	char b[30] = {
   "asdasdasda"};
	char* p;
	p = b;
	auto x = strcasecmp(p,a);
	printf("%d\n",x);
}

输出:

97

3、strncasecmp函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值