如果我有一个搜索条件:She likes to watch tv
text.txt
包含一些句子的输入文件,例如:
I don't know what to do. She doesn't know that it's not good for her health. She likes to watch tv but really don't know what to say. I don't blame her, but it's not her fault. This was just a test text. This is the end.
我想在文本文件中搜索字符串,并返回包含字符串的句子,加上它之前和之后的句子。
输出应如下所示:
She doesn't know that it's not good for her health. She likes to watch tv but really don't know what to say. I don't blame her, but it's not her fault.
因此,它输出匹配搜索词之前的句子、包含搜索词的句子和搜索词之后的句子。