Just had an interesting argument in the comment to one of my questions. My opponent claims that the statement ""
does not contain ""
is wrong.
My reasoning is that if ""
contained another ""
, that one would also contain ""
and so on.
Who is wrong?
P.S.
I am talking about a std::string
P.S. P.S
I was not talking about substrings, but even if I add to my question " as a substring", it still makes no sense. An empty substring is nonsense. If you allow empty substrings to be contained in strings, that means you have an infinity of empty substrings. What is the point of that?
Edit:
Am I the only one that thinks there's something wrong with the function std::string::find
?
C++ reference clearly says
Return Value: The position of the first character of the first match.
Ok, let's assume it makes sense for a minute and run this code:
string empty1 = "";
string empty2 = "";
int postition = empty1.find(empty2);
cout << "found \"\" at index " << position << endl;
The output is: found "" at index 0
Nonsense part: how can there be index 0 in a string of length 0? It is nonsense.
To be able to even have a 0th position, the string must be at least 1 character long.
And C++ is giving a exception in this case, which proves my point:
cout << empty2.at( empty1.find(empty2) ) << endl;
If it really contained an empty string it would had no problem printing it out.
subset
andsubstring
, they are not the same. Also consider in C++ a string s with length 10.s.substring(0,0)
,s.substring(1,0)
, etc. There are 10 such substrings that return the empty string. If you havestring s = "";
, thens.substring(0,0)
also returns the empty string. – Princelya
equals setb
,a
must contain all parts ofb
. An empty string equals an empty string, therefore it must contain it as well. Also, if one can get an empty string as a substring from any string, does that not imply that any string must contain an empty string? – Forland