Re: Search Array

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 19 Jan 2009 14:22:28 -0800, Jonathan Wood <jwood@xxxxxxxxxxxxxxxx> wrote:

I've created a simple array of unsorted strings.

Is there a SIMPLE way to see if the array contains a string while ignoring case, without writing my own loop?

I don't mind writing my own loop but if there's already something to do this, I'd like to find it. I've found all sorts of complex stuff but nothing to perform this rather trivial task.

It is a rather trivial task. Any particular reason you want to avoid the extra few lines required for an explicit loop?

You can use Array.Find<T>() or Enumerable.Contains<TSource>(). Either of those will allow you to provide a predicate that does the exact comparison you want (Array.Find<T>() is probably easier, since it allows you to provide the predicate directly, rather than wrapping it in an interface implementation).

But loops aren't exactly evil or anything. It wouldn't be the end of the world if you had to write one yourself. :)

Pete
.



Relevant Pages

  • Re: Search Array
    ... Is there a SIMPLE way to see if the array contains a string while ignoring case, without writing my own loop? ... I don't mind writing my own loop but if there's already something to do this, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Search Array
    ... "Arne Vajhøj" wrote in message ... Is there a SIMPLE way to see if the array contains a string while ignoring case, without writing my own loop? ... I don't mind writing my own loop but if there's already something to do this, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Search Array
    ... "Stefan L" wrote in message ... if (Array.IndexOf(myStrings, stringToFind)>= 0) ... Is there a SIMPLE way to see if the array contains a string while ignoring case, without writing my own loop? ... I don't mind writing my own loop but if there's already something to do this, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: asm grep
    ... ignoring "lines" (find the beginning/end of the line in which the match ... It's probably easier to implement with a small loop now that you want to ... especially since tracking multiple character ...
    (alt.lang.asm)
  • Re: error reading from socket
    ... I have a problem reading ... from the socket. ... You are ignoring the return value of soc->recv, ... I am assuming that I need a loop, but I cannot figure out which one. ...
    (comp.unix.solaris)