c - strstr 匹配 c 中的第一次出现

标签 c strstr

我想知道如果 str1 包含以下字符串,我如何匹配 str1 中的字符串 "Just":

"this is Just/1.1.249.4021 a test" 
// "Just" will always be the same

我正在尝试使用 strstr 来匹配它,但由于 /...

目前还无法匹配

关于如何匹配它有什么建议吗?谢谢

最佳答案

这对我有用 - 你呢?

#include <string.h>
#include <stdio.h>
int main(void)
{
    char haystack[] = "this is just\2323 a test";
    char needle[] = "just";
    char *loc = strstr(haystack, needle);
    if (loc == 0)
        printf("Did not find <<%s>> in <<%s>>\n", needle, haystack);
    else
        printf("Found <<%s>> in <<%s> at <<%s>>\n", needle, haystack, loc);
    return(0);
}

关于c - strstr 匹配 c 中的第一次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2542733/

相关文章:

c - 如果第二个字符串在开头,strstr 会返回与第一个字符串相同的指针吗?

c - 在 autotools 项目中添加 CFLAG(例如 -std=gnu99)的位置

c - 指针:表达式不可赋值

c - 如何获取 "\r\n\r\n"之前的子串

php - 在开关 php 中使用 strstr

c++ - strstr 在 codeforces 上的 C++ 4.7 中不起作用

c - 我怎样才能找到两个子字符串

代码漏洞

c - 函数内部的第二个 scanf 不起作用......程序不会在第二个 scanf 处停止?

c - 指向当前函数的指针