>Hi,
>
>I need to check if a string is within another string. Here is an example:
>
>
> if (!LongString.Contains(ShortString))
> {
> // do something
> }
>
>
>The problem I have is when the short string (ShortString) is empty (""), "do something" never does anything. Of course I can get around the problem by adding to the IF ShortString.Length = 0 || . But I was wondering, can I change the .Contains somehow to make it work with empty string?
Nothing you can do about how 'Contains' works. Maybe :
if (string.IsNullOrEmpty(ShortString) || !LongString.Contains(ShortString))
or you could get fancy and write your own extension method :-}