example:
string[] StringArray = {"aaa","bbb","ccc","ddd","eee"};
string find = "bbb";
List
foreach (string Block in StringArray)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Block, find,
System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
FoundList.Add(Block);
}
else
{
//do nothing
}
}
string[] FoundArray = FoundList.ToArray();
it will create FoundArray = {"bbb"} and I wish to find int i such that
StringArray[i] = FoundArray[0]
is true and for senarios where FoundArray has multiple entries I plan to loop it. Any help would be much appreciated.
Amit ChoudharyPosted Sep 5, 2011, 12:51 PM
VulpesPosted Sep 5, 2011, 10:08 AM
However, StringArray.IndexOf(Block), will always give you the same index, even if there are duplicates found so you'd need to modify his code to use a 'for' rather than a 'foreach' loop.
The code for the Tuple approach would be:
alecPosted Sep 5, 2011, 9:59 AM
Amit ChoudharyPosted Sep 5, 2011, 9:56 AM
so you code would look like
Dictionary
and inside the loop write below code with the FoundList.Add(Block)
foundStrings.Add(StringArray.IndexOf(Block), Block);
now you have everything you want..so you can loop through the dictionary and match the FoundList array Element..
VulpesPosted Sep 5, 2011, 9:55 AM
Here's a simple one:
If you're using .NET 4.0, you could also use a List