【发布时间】:2015-06-28 14:10:45
【问题描述】:
我有一个字符串变量 s,它就像段落的组合。 例如,
Passages provides funeral and burial products.
Our products are meant to align with your values and bring you comfort.
Our products allow you to offer personalization , flexibility and innovative choices, helping you provide services to a wider range of customers.
我必须将字符串变量设为这种形式:
Passages provides funeral and burial products. Our products are meant to align with your values and bring you comfort. Our products allow you to offer personalization, flexibility and innovative choices, helping you provide services to a wider range of customers.
另外,单词之间的多余空格(或'.' 和单词的第一行之间的空格)将被删除,并转换为单个空格和',','之前的任意数量的空格。'。或者 ';'将被删除。
我是java新手。谁能告诉我怎么做?
【问题讨论】:
-
看看Java中的正则表达式。
-
您的规则似乎不一致。如果您使用 exact 格式规则编辑您的问题,您可能会得到一个有用的答案。
-
您可以遍历字符串并使用条件复制所有不是\n或任何其他字符的字符。
-
我已经实现了所有规则,除了如何删除单词和',','之间的所有空格。或';'(单词首先出现)