I want to check if a string is a strictly a subset of another string. For this end I used boost::contains and I compare the size of strings as follows:
#include <boost/algorithm/string.hpp>
#include <iostream>
using namespace std;
using namespace boost::algorithm;
int main()
{
string str1 = "abc news";
string str2 = "abc";
//strim strings using boost
trim(str1);
trim(str2);
//if str2 is a subset of str1 and its size is less than the size of str1 then it is strictly contained in str1
if(contains(str1,str2) && (str2.size() < str1.size()))
{
cout <<"contains" << end;
}
return 0;
}
Is there a better way to solve this problem? Instead of also comparing the size of strings?
Example
- ABC is a proper subset of ABC NEWS
- ABC is not a proper subset of ABC