indexofany vs contains

Just curious what is the difference between .indexofany and .contains.



LVL 8
bman9111Asked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Contains takes a string and returns a bool if it is found in the search string.

IndexOfAny takes an array of characters to search for and returns the index position of the first one, if any, found.
0
 
bman9111Author Commented:
ok....is there a way to make contains look for a word no matter what the case maybe be.

I noticed that is i do a .contains("TT")
if only will look for TT, but what if it is Tt or TT....

Right now I am doing like 3 statement to achieve it to find it. Is that correct?
0
 
Carl TawnSystems and Integration DeveloperCommented:
Use ToLower() on the string to convert it to lowercase for the comparison:
 
            string s1 = "This is TT";
            MessageBox.Show(s1.ToLower().Contains("tt").ToString());
0
All Courses

From novice to tech pro — start learning today.