3

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.

edit//

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

1
  • 2
    So it's Java or C#? Edit either question header or tag. Commented Dec 26, 2011 at 4:24

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

1 Comment

your correct.. it would have to be looped thru sorry about that Adam my eyes saw string[]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.