【发布时间】:2019-03-02 23:47:00
【问题描述】:
我有一个哑字符串
Today the auto industry is booming. Automated machines are big part of it and it's working great. They are doing very big autonomous work.
我希望能够提供一个关键字字典作为List<string>。
然后我想在我的文本中搜索这些关键字。如果找到关键字,请检查前后是否包含空格。如果是,什么也不做。如果不包含,则在之前或之后添加空格。所以关键字可以是一个单词的开头中间或结尾的一部分。所以基本上在文本中使关键字成为单个单词。
示例关键字:auto, work, the
为了我的文字
Today the auto industry is booming. Automated machines are big part of it and it's working great. They are doing very big autonomous work.
结果应该是:
Today the auto industry is booming. Auto mated machines are big part of it and it's work ing great. The y are doing very big auto nomous work .
【问题讨论】:
-
为什么不用正则表达式?这感觉是正则表达式的最佳时机......
-
我不太懂正则表达式……但当然没关系。
-
你可以搜索,我认为这是一个经典的正则表达式。见:stackoverflow.com/questions/5650909/…
-
因为它应该是一个单词
-
对于每个单词,将单词替换为
" word "。然后将" word"(前面两个空格)替换为" word",将"word "(末尾两个空格)替换为"word ",以处理双空格问题(即那里已经有空格)。