您可以使用正則表達式。
實施例:
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])' –