在C#中,什么是在字符串中查找子字符串并在单词之后跟随搜索到的句子(例如在字符串中)检索子字符串的正确方法:
string str = "On the screen the faint, old, robed figure of Mercer toiled upward, and all at once a rock sailed past him.";
搜索子字符串:
string find = "figure of";
获得所需的输出:
figure of Mercer
答案 0 :(得分:0)
您可以尝试此模式([inputString] +(\\w+))
使用正则表达式group
和空格获取单词。
string search = "figure of";
string str = "On the screen the faint, old, robed figure of Mercer toiled upward, and all at once a rock sailed past him.";
string regex_Str = string.Format("({0} +([\\w+]+))", search);
var result = new Regex(regex_Str).Match(str);
Console.WriteLine(result.Value);