0

我想用 C++ 编写一个程序来获取一个句子并在每个单词和标点符号之间插入一个空格!在 sed 脚本中,这是通过以下表达式完成的:

sed -e "s/,\([^0-9]\)/ , \1/g" -e "s/\.\([^0-9]\)/ . \1/g" -e 's/\.[ ]*$/ ./g' -e "s/\'/ \' /g" -e 's/?/ ?/g' -e 's/\`\`/ `` /g' -e "s/\' \'/''/g" -e 's/(/ ( /g' -e 's/)/ ) /g' -e 's/ \. \([^$]\)/. \1/g' -e "s/\' s/\'s/g" -e "s/\"\([^\"]*\)\"/\" \1 \"/g" $1 | sed -e "s/\"\([^\"]*\)\"/\`\`\1''/g" 

但我不知道我应该如何在 Windows 中的 c++ 中做到这一点!例如:应该转换为“现在的问题:他能否表现得更像是强硬的泰迪罗斯福。” 必须转换为“现在的问题:他能否表现得更像是强硬的泰迪罗斯福。” 所以像“-”这样的标点符号或例如“。” 在“不”。句子中不应间隔,但不依赖于单词或短语的其他标点符号应间隔。

4

1 回答 1

3

Since you already know how to handle this using regular expressions I think you can try to use Boost.Regex in order to archive the same with C++.

于 2010-05-26T05:42:23.410 回答