1

I'm trying to search my datatable for a possible string pattern. For example I want to search the term "nin" in column A of my datatable, I want it to show all of the rows which has the pattern "nin", even if it is in uppercase or in other format. What I'm currently doing is this:

for(var f = 0; f < dt.Rows.Count; f++)
{
string temp = "nin";
string PositionName = dt.Rows.[f]['ColumnA'].ToString();
int tempColCount = PositionName.Length;
bool searchTerm = PositionName.Substring(0, tempColCount).Contains(temp);
}

But all I'm getting are rows that have the exact pattern as "nin". How do I get the other formats of the same pattern? I'm thinking something like Regex here but I can't understand the tutorials online.

marchemike
  • 3,179
  • 13
  • 53
  • 96

1 Answers1

1

Fast way to search for, depending on culture an ignoring upper / lower:

CompareInfo compInf = CultureInfo.CurrentCulture.CompareInfo;
int compResult = compInf.IndexOf(searchInString, searchForString, CompareOptions.IgnoreCase);
marsh-wiggle
  • 2,508
  • 3
  • 35
  • 52
  • This won't be fast given the data is coming from a database and all the OP needs to do is apply a `LIKE` clause. – Moo-Juice Jul 07 '14 at 06:49