Jon
Fri May 09 16:02:46 CDT 2008
SMJT <shanemjtownsend@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?
There exists an empty string beginning at every place in the string. I
can't think of any definition of containment for which that's not true.
> >>"AnyOldText".IndexOf("") == 0;
> yes but so does "AnyOldText".IndexOf("A") so which is it position 0 an
> empty string or a text stream?
Both, just as "An" is also at the start, and so is "Any".
> 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.
Asking for the index of an empty string isn't a question which can
yield useful information though. Ask a silly question, get a silly
answer.
> >>"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.
The logic seems fairly clear to me: if x+y=z, then z contains y, right?
Now apply the same logic with x="abc", y="" and thus z="abc".
> >>("").Contains("")
> Yeah, ok that makes sense and I expected this to be the only time
> Contains returned TRUE.
Why?
--
Jon Skeet - <skeet@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com