【发布时间】:2014-02-10 06:10:16
【问题描述】:
所以我在用 Ruby 编码,我有几句话:
The sky above the port was the color of television, tuned to a dead channel. "It's not like I'm using," Case heard someone say, as he shouldered his way through the crowd around the door of the Chat. "It's like my body's developed this massive drug deficiency." It was a Sprawl voice and a Sprawl joke. The Chatsubo was a bar for professional expatriates; you could drink there for a week and never hear two words in Japanese.
而且我需要在不改变结构的情况下修改段落中的每个单词。我最初的想法是在空格上拆分然后重新加入,但问题是你也会得到标点符号。如果您拆分以便只听单词,则很难重新加入,因为您不知道正确的标点符号。
有没有比传统的拆分、映射、加入组合更好的方法来做到这一点?或者也许只是一个很好的拆分正则表达式,所以很容易重新加入?
【问题讨论】:
-
我想这取决于你想对每个单词做什么......
-
你想让这句话有意义吗?因为否则你可以只分割空格和所有已知的标点符号并替换所有标记并重新加入
标签: ruby algorithm paragraphs