Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to check if a string contains another string in C? [duplicate]

People also ask

How do you check if a string contains another string in c?

The function strstr returns the first occurrence of a string in another string. This means that strstr can be used to detect whether a string contains another string. In other words, whether a string is a substring of another string.

How do you check if a string is a subset of another?

Simple Approach: The idea is to run a loop from start to end and for every index in the given string check whether the sub-string can be formed from that index. This can be done by running a nested loop traversing the given string and in that loop running another loop checking for sub-string from every index.

How do you check if two characters in a string are the same?

To find whether a string has all the same characters. Traverse the whole string from index 1 and check whether that character matches the first character of the string or not. If yes, then match until string size. If no, then break the loop.

How do I check if a string contains something?

The includes() method returns true if a string contains a specified string. Otherwise it returns false .


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

strstr(request, "favicon") != NULL