我有两根弦。可以说`
str1="One Two Three";
and
str2="two";
我想知道是否有任何函数可以检查第一个字符串中第二个字符串的匹配,并返回指向第一个字符串的指针,例如strstr()
,但它不会将相同的字母(大写或小写)视为两个不同的字符。
对于我的示例,该函数应该找到匹配项str2
在第一个字符串中,尽管是大写的"T"
, of "Two"
.
从联机帮助页来看strstr
:
STRSTR(3) Linux Programmer's Manual STRSTR(3)
NAME
strstr, strcasestr - locate a substring
SYNOPSIS
#include <string.h>
char *strstr(const char *haystack, const char *needle);
#define _GNU_SOURCE
#include <string.h>
char *strcasestr(const char *haystack, const char *needle);
DESCRIPTION
The strstr() function finds the first occurrence of the substring needle in
the string haystack. The terminating '\0' characters are not compared.
The strcasestr() function is like strstr(3), but ignores the case of both
arguments.
RETURN VALUE
These functions return a pointer to the beginning of the substring, or NULL if
the substring is not found.
所以你要找的是strcasestr
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)