tags:

views:

70

answers:

1

We have a char and a char[].

What would be the most efficient (or, failing that, just simplest) way of finding out whether the char is located inside of char[]?

The language used is D.

Thanks!

+3  A: 

if it's not sorted, the only thing you can do is loop through and check each element, breaking or returning if a match is found.

char char1 = ...;
char[] chars = ...;

foreach(char char2; charArray)
  if (char2==char1)
      return true;
return false;

forgive me if that doesn't compile - i'm rusty with d.

pstanton