c - strstr() 函数类似,忽略大写或小写

标签 c string

我有两个字符串。让我们说`

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/

相关文章:

c++ - 记录编译源码的时间

c++ - 从 LuaJIT 调用 C++ DLL

链表归并排序的复杂性

java - 字符串搜索的性能

python - 你如何在 Python 中可视化一个巨大的整数?

C - 警告 [pe069] 整数转换导致截断

C编程,指针的使用

java - 如何检查只包含一个单词的字符串。如果一个字符串有一个句子,它应该返回 false

mysql - MySql 中的通配符类型

c++ - 是否可以创建一个字符串数组,如果可以,为什么我会收到此错误 : error: expected expression?