您可以使用正则表达式。
实施例:
string input = "This is a test, again I am test TECHNICAL: I need to extract this substring starting with testing. 8. This is test again and again and again and again";
string pattern = @"(TECHNICAL|JUSTIFY).*?(10|[1-9])";
System.Text.RegularExpressions.Regex myTextRegex = new Regex(pattern);
Match match = myTextRegex.Match(input);
string matched = null;
if (match.Groups.Count > 0)
{
matched = match.Groups[0].Value;
}
//Result: matched = TECHNICAL: I need to extract this substring starting with testing. 8
我会使用这个表达式:'(技术| JUSTIFY)*([1-9] | 10)'。?。 – MRAB
我稍微改变了字符串,我得到了错误的结果。我的新字符串是字符串输入=“1.TECHNICAL:这是一个测试BLAH BLAH BLAH RAL ESTATE。6.测试描述”。当我申请你的正则表达式时,我只得到1而不是TECHNICAL:这是一个测试BLAH BLAH BLAH REAL ESTATE。 – Anjali5
@MRAB是的,谢谢,这是更简单的,我用你的,但只使'10'先这样'(TECHNICAL | JUSTIFY)。*?(10 | [1-9])' –