从c#中的字符串中查找字符串 [英] find string from string in c#
本文介绍了从c#中的字符串中查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从其他字符串中找到字符串,如>
字符串a =如何从anoher字符串中找到字符串;(此字符串或结果字符串应该不是静态的)
i希望结果就像查找字符串;
how can i find string from anoher string like>
string a= "how can i find string from anoher string";(this string or result string should not static)
i want result is like "find string";
推荐答案
string a = "this is a string";
string b = "is a";
bool isBinA = a.contains(b);
isBinA将在这种情况下成立。
isBinA will be true in this situation.
嗨chetan,
Firtly - 两个第一个解决方案都是为了你的简单目的,这很好。
我想建议你学习一些正则表达式,这些对于搜索目的非常有用,对于开发人员来说基本上是必备的工具。 />
查看一个小例子:
Hi chetan,
Firtly - Both the first solutions are of great for your simple purpose.
I want to suggest however, that you learn a bit about Regular Expressions, those will prove extremely useful for search purposes, and are basically a must tool for developers.
See a little example:
string TheText = "Here comes your bulk of text with the pattern to find.";
string WhatToFind_Pattern = "the pattern to find"; // all you have to do is learn some Regex Expressions (see links below the code block ;)
if (System.Text.RegularExpressions.Regex.IsMatch(TheText, WhatToFind_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
// Do Stuff
}
如果你想进入正则表达式,有用的链接:
- 轻松学习正则表达式(RegEx) [ ^ ]
- 使用正则表达式进行验证变得简单 [ ^ ]
- Regex快速参考 [ ^ ]
干杯,
Edo
Useful links in case you want to get into Regex:
- Learn Regular Expressions (RegEx) with Ease[^]
- Validation with Regular Expressions Made Simple[^]
- Regex Quick Reference[^]
Cheers,
Edo
string a = "asdfghijklmnopqrstuvxz";
string b = "hijklm";
bool c = (a.IndexOf(b) > -1);
这篇关于从c#中的字符串中查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文