On Fri, 09 May 2008 01:14:18 -0700, SMJT <sh*************@hotmail.com
wrote:
Thanks for all the replies and explanations.
>>(whole+part).Contains( part) return true ALWAYS no? ...
Fair enough, IF an empty string was part of the original string, but
if a string has any contents, how can any part of it be empty?
But that's just it. Every zero-length substring of your original string
is "empty". A string of length N has N zero-length substrings in it. One
for each character position in the string of length N.
>>"AnyOldText".IndexOf("") == 0;
yes but so does "AnyOldText".IndexOf("A") so which is it position 0 an
empty string or a text stream?
What do you mean by "text stream"?
In any case, for a string of length N, there are N+1 strings you can pass
to IndexOf() that will return 0. The fact that you can get
"AnyOldText".IndexOf("A") to return 0 is no more a problem than that you
can also get "AnyOldText".IndexOf("An"), "AnyOldText".IndexOf("Any"), etc.
to return 0.
There's nothing wrong at all for allowing more than one string to return
the same character index for the IndexOf() method, including the empty
string "".
And "AnyOldText".IndexOf("",1) == 1; "AnyOldText".IndexOf("",2) ==
2; "AnyOldText".IndexOf("",3) == 3; etc ... So by that logic there is
an empty string at each of these positions and text, which although
theoretically true isn't exactly useful information.
It's not just theoretically true. It's logically true. At every
character position, there are a number of possible substrings that can be
found at that position. Including the zero-length substring "".
>>"abc" + "" = "abc", it means that "abc" contains ""
No it doesn't, it just means you concatenated nothing to the original
string so I would expect it to remain unchanged.
I agree that example was a bit awkward. However, it's a specific example
of making the statement: "string A contains string B if and only if there
exist strings A1 and A2 such that A1 + B + A2 = A". Since "" is a valid
string, then for string "abc", we have as candidates for A1 the strings
"", "a", "ab", and "abc", and as candidates for A2 the strings "abc",
"bc", "c", and "", respectively.
>>("").Contains("")
Yeah, ok that makes sense and I expected this to be the only time
Contains returned TRUE.
It's clear you expected that. But your expectation wasn't correct, or
even logical. The Contains() and IndexOf() methods would be logically
inconsistent if they treated "" differently from any other string. So
they don't. The empty string "" follows all of the same rules for
Contains() and IndexOf() that other strings follow.
Pete