【发布时间】:2012-04-13 12:03:43
【问题描述】:
我似乎找不到解决这个问题的好方法。我收到了一份关于丢失或被盗设备的报告,其中包含一系列字符串。我一直在表单的其余部分使用string.IndexOf 函数,它运行良好。此问题与说明设备是否丢失或被盗的字段有关。
例子:
“丢失还是被盗?丢失”
“丢失还是被盗?被盗”
我需要能够阅读此内容,但当我阅读 string.IndexOf(@"Lost") 时,它总是会返回丢失,因为它在问题中。
不幸的是,我无法以任何方式更改表单本身,并且由于提交方式的性质,我不能只编写代码来敲掉字符串的前 15 个左右字符,因为这可能太少了在某些情况下。
我真的很想要 C# 中的一些东西,它允许我在找到第一个结果后继续搜索字符串,这样逻辑看起来像:
string my_string = "Lost or Stolen? Stolen";
searchFor(@"Stolen" in my_string)
{
Found Stolen;
Does it have "or " infront of it? yes;
ignore and keep searching;
Found Stolen again;
return "Equipment stolen";
}
【问题讨论】:
-
总是有一个问号?分开。
-
I've been using the string.IndexOf function through the rest of the form and it works quite well我们这里说的是什么形式?
标签: c# string search full-text-search