Take the 2-minute tour ×

suppose there is a string like this

string temp2 = "hello";
char[] m = { 'u','i','o' };

Boolean B = temp2.Compare(m);

I want to check if the string contains my array of character or not? I am trying but it is not taking.On compiling the message

temp2.Compare(m) should be String type

is coming. Means it follows string.compare(string); I hope it is not the way there should be some way to do that.


I have Corrected the line String.Compare return the Boolean Value

share|improve this question
So it's Java or C#? Edit either question header or tag. –  Frozen Spider Dec 26 '11 at 4:24
@FrozenSpider In C# –  Raja Dec 26 '11 at 4:26
add comment

2 Answers

up vote 4 down vote accepted

If what you want to determine is whether the string contains any of the characters in your array, you can use the string.IndexOfAny function.

bool containsAny = temp2.IndexOfAny(m) >= 0;
share|improve this answer
Thanks It's Working –  Raja Dec 26 '11 at 4:38
@DJKRAZE Contains does not accept a char[]. –  Adam Robinson Dec 26 '11 at 13:46
your correct.. it would have to be looped thru sorry about that Adam my eyes saw string[] –  DJ KRAZE Dec 26 '11 at 13:49
add comment
using namespace std;
int main()
string str = "Arne Kristoffer rules";
if (str[x] == "a")
cout << str[x];
return 0;

Well, this is just a silly example program, but I hope you see. Thanks! :)

share|improve this answer
add comment

Your Answer


