![]() |
A substring of a string is a contiguous sequence of characters within that string. In simpler terms, a substring is a part of a larger string that appears consecutively in it. In this article, we are going to learn how to do a case-insensitive search for a substring in C++. Example: Input: Case-Insensitive Search for a Substring in C++To do a case-insensitive search for a substring in C++, we can use the std::search() function with a custom comparator that converts the characters to be compared into lowercase using tolower() and then performs the comparison. Syntax of std::search()search(first1, first2, second1, second2, comp); here,
This function will return the iterator to the first occurrence of the substring. If the substring is not found, then it will return the iterator to the end of the main string. C++ Program to to Do Case-Insensitive Search for a SubstringC++
Output
Substring found Time Complexity: O(N * M), where N is the size of the original string and M is the size of the substring to be searched. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |