Below is my string array :
string[] arr = {
"region1.mp3,region1-sub.mp3,region1-sub1.mp3,region2-sub.mp3",
"region2.mp3,region2-Sub1.mp3",
"region3.mp3"
};
Below is my value which I am trying to search in above string array and get index:
string searchItem = "region1-sub1.mp3";
This is how I am trying to search but getting -1 (-1 indicates search not found I guess):
int index = Array.FindIndex(arr, t => t == searchItem); // -1
I understand that because my records in string array are comma separated that is why this search is failing.
So any other method which can help me find index without looping and generating new string array?
Expected Output : 0
Contains??int index = Array.FindIndex(arr, t => t.Split(',').Contains(searchItem));,has a special meaning here. If you want to search individual values, you have to split the strings first, or usestring.Containsor a Regex for better performanceIsMatch, not even that.Valueis a string created. This saves CPU and RAM and avoids the penalty of GCing a few thousands strings