我需要在文本中搜索,但是有可能在richtextbox.Find("something");
有多个选项吗?例如richtextbox.Find("something" or "somethingelse");
c#在文本中找到东西
0
A
回答
0
您可以实现这样的事情(的扩展方法FindAny
为RichTextBox
):
public static class RichTextBoxExtensions {
public static int FindAny(this RichTextBox source, params String[] toFind) {
if (null == source)
throw new ArgumentNullException("source");
else if (null == toFind)
throw new ArgumentNullException("toFind");
int result = -1;
foreach (var item in toFind) {
if (null == item)
continue;
int v = source.Find(item);
if ((v >= 0) && ((result < 0) || (v < result)))
result = v;
}
return result;
}
}
....
int result = richtextbox.FindAny("something", "somethingelse");
+0
工作。谢谢。但是底部的第三行必须是'return v;',而不是'return = v;' – Stepik
+0
@Stepik:是的,你说得很对;对错字感到抱歉。它应该是'result = v;',我已经编辑了答案。 –
相关问题
- 1. C++ STL map.find()找不到我的东西
- 2. C#XPath没有找到任何东西
- 3. C - 虽然(东西||东西)
- 4. 找到这个东西,并替换它后面的东西
- 5. 如何找到没有东西时返回其他东西?
- 6. 崇高的文字2-在页面上快速找到东西
- 7. 期待水豚找不到东西?
- 8. Excel - 找到缺少的东西?
- 9. WatiN没有找到任何东西
- 10. XmlElement.SelectNodes(..) - 找不到任何东西..帮助?
- 11. xPath找不到任何东西,但*
- 12. 找到有买东西的客户不
- 13. Physics2D.Raycast没有找到任何东西
- 14. 在C++中寻找类似getrusage()的东西
- 15. C++文件IO - 无法找到文件IO相关的东西的方法
- 16. 在Inform 7中,通过名称在不同文字中找到一个东西
- 17. 如何回响在C#中的东西在.aspx文件中
- 18. VS2010不断寻找东西
- 19. 在==东西或别的东西,
- 20. CoreAudio的东西从C++到Swift
- 21. jQuery选择是查找其文本没有的东西
- 22. 东西viewmodel到html.actionlink
- 23. 如何从一个文本文件读取多个东西到C++
- 24. 在eclipse中找不到任何东西“Source not found”
- 25. 如果在.find()中找不到任何东西,mongoose
- 26. 正则表达式在字符串中找到一些东西
- 27. 找到东西(但没有在生产中)
- 28. 在Eclispe中安装东西 - 未找到存储库“osgi.bundle”
- 29. 使用Shell脚本在C程序中更改某些东西
- 30. 在文本框中的中间按钮滚动的东西
字符串。载有(“文本的一部分”)的伎俩 – SnakeFoot