Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare string with character in C#

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

like image 926
Raja Avatar asked Jul 25 '26 17:07

Raja


1 Answers

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;
like image 96
Adam Robinson Avatar answered Jul 28 '26 05:07

Adam Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!