我有两个字符串。让我们说`
str1="One Two Three";
和
str2="two";
我想知道是否有任何函数可以检查第一个字符串中的第二个字符串是否匹配,并返回指向第一个字符串的指针,比如 strstr()
,但它不会将相同的字母(大写或小写)视为两个不同的字符。
对于我的示例,该函数应该在第一个字符串中找到 str2
的匹配项,尽管 “T”
是大写的 “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 *<b><u>strcasestr</u></b>(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.
<b>The strcasestr() function is like strstr(3), but ignores the case of both
arguments.</b>
RETURN VALUE
These functions return a pointer to the beginning of the substring, or NULL if
the substring is not found.
所以你要找的是 strcasstr
。
关于c - strstr() 函数类似,忽略大写或小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27303062/