【问题标题】:Searching for string patterns c#搜索字符串模式c#
【发布时间】:2014-07-07 06:28:40
【问题描述】:

我正在尝试在我的数据表中搜索可能的字符串模式。例如,我想在我的数据表的 A 列中搜索术语“nin”,我希望它显示所有具有模式“nin”的行,即使它是大写或其他格式。我目前正在做的是这样的:

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);
}

但我得到的只是具有“nin”确切模式的行。如何获得相同模式的其他格式?我在这里想的是 Regex 之类的东西,但我无法理解在线教程。

【问题讨论】:

标签: c# regex string search


【解决方案1】:

快速搜索方式,取决于文化忽略上/下:

CompareInfo compInf = CultureInfo.CurrentCulture.CompareInfo;
int compResult = compInf.IndexOf(searchInString, searchForString, CompareOptions.IgnoreCase);

【讨论】:

  • 这不会很快,因为数据来自数据库并且所有 OP 需要做的就是应用 LIKE 子句。
猜你喜欢
  • 2012-08-30
  • 2021-11-24
  • 2012-11-01
  • 2021-12-20
  • 1970-01-01
  • 1970-01-01
  • 2012-04-13
相关资源
最近更新 更多