Using string_view to search into string is very efficient, specially if you want to extract a substr without create a new string object like std::string::substr does.
Then:
string sTest(".......9999.......");
string_view vsTest = sTest;
cout << vsTest.substring(7,4); //That is more efficient then
cout << sTest.substring(7,4); //that one
On C++11 I usually wrote a search of substring into a string like that
string s_Sub("+++++++9999+++++++");
string sTest(".......9999.......");
cout << (sTest.find(s_Sub.substr(7,4))) << '\t';
I thought the natural step to C++17 is:
string s_Sub("+++++++9999+++++++");
string sTest(".......9999.......");
string_view vsSub = s_Sub;
cout << (sTest.find(vsSub.substr(7,4))) << '\t';
But surprisingly it doesn't compile on gcc 5.4.0.
error: no matching function for call to ‘std::__cxx11::basic_string<char>::find(std::experimental::fundamentals_v1::basic_string_view<char>)’|
That is because my compiler or because std::string::find won't be ready to receive a string_view as parameter?
In my opinion, create a new string_view object to every string (sTest in this case) is not the best practice despite it is cheap because because it seems totally unnecessary.