Given a sentence as a string str and a word word, the task is to check if the word is present in str or not. A sentence is a string comprised of multiple words and each word is separated with spaces.
Input: str = “Geeks for Geeks”, word = “Geeks”
Output: Word is present in the sentence
Input: str = “Geeks for Geeks”, word = “eeks”
Output: Word is not present in the sentence
Approach: In this algorithm, stringstream is used to break the sentence into words then compare each individual word of the sentence with the given word. If the word is found then the function returns true.
Note that this implementation does not search for a sub-sequence or sub-string, it only searches for a complete single word in a sentence.
Below is the implementation for the case-sensitive search approach:
Below is the implementation for the case-insensitive search approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the word with most anagrams in a given sentence
- Sums of ASCII values of each word in a sentence
- Program to replace a word with asterisks in a sentence
- Program for length of the longest word in a sentence
- Print longest palindrome word in a sentence
- Print each word in a sentence with their corresponding average of ASCII values
- Java program to count the characters in each word in a given sentence
- Most frequent word in first String which is not present in second String
- Check a given sentence for a given set of simple grammer rules
- Check if given words are present in a string
- Check whether the Average Character of the String is present or not
- Python | Check if a Substring is Present in a Given String
- Frequency of smallest character in first sentence less than that of second sentence
- C program to find and replace a word in a File by another given word
- Longest Common Prefix using Word by Word Matching
- C program to Replace a word in a text by another given word
- Check if binary representations of 0 to N are present as substrings in given binary string
- Check if the given string of words can be formed from words present in the dictionary
- Calculate the difficulty of a sentence
- Snake case of a given sentence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.