I have to check if the particular string begins with another one. Strings are encoded using utf8, and a comparison should be case insensitive.
I know that this is ve
Using the stl regex classes you could do something like the following snippet. Unfortunately its not utf8. Changing str2
to std::wstring str2 = L"hello World"
results in a lot of conversion warnings. Making str1
an std::wchar
doesn't work at all, since std::regex doesn't allow a whar input (as far as i can see).
#include
#include
#include
int main()
{
//The input strings
std::string str1 = "Hello";
std::string str2 = "hello World";
//Define the regular expression using case-insensitivity
std::regex regx(str1, std::regex_constants::icase);
//Only search at the beginning
std::regex_constants::match_flag_type fl = std::regex_constants::match_continuous;
//display some output
std::cout << std::boolalpha << std::regex_search(str2.begin(), str2.end(), regx, fl) << std::endl;
return 0;
}