检查字符串是否包含C中的另一个字符串的简单方法? [重复]

时间:2020-12-19 01:33:56

This question already has an answer here:

这个问题在这里已有答案:

I'm pretty new to the language. Let's say I have a string from an HTTP request, such as

我对这门语言很陌生。假设我有来自HTTP请求的字符串,例如

char * request = "GET /favicon.ico HTTP/1.1";

And I specifically want to know if favicon is in that request, perhaps with a boolean value. What is a relatively simple way to go about this? I know how to do it in Java, but I'm more lost with C.

我特别想知道favicon是否在该请求中,也许是一个布尔值。有什么比较简单的方法呢?我知道如何在Java中做到这一点,但我更加迷失于C.

Thanks!

谢谢!

2 个解决方案

#1


62  

if (strstr(request, "favicon") != NULL) {
    // contains
}

#2


18  

strstr(request, "favicon") != NULL

#1


62  

if (strstr(request, "favicon") != NULL) {
    // contains
}

#2


18  

strstr(request, "favicon") != NULL