gpt4 book ai didi

java - 删除句子和段落之间的各种额外空格

转载 作者:行者123 更新时间:2023-11-29 06:34:45 24 4
gpt4 key购买 nike

我想删除句子之间的各种多余空格,并将其作为一个字符串进行某些处理

例如:

The meaning of the phrase "ice cream" varies from one country to another. Phrases 
such as "frozen custard", "frozen yogurt", "sorbet", "gelato" and others are used
to distinguish different varieties and styles.

In some countries, such as the United States, the phrase "ice cream" applies only
to a specific variety, and most governments regulate the commercial use of
the various terms according to the relative quantities of the main ingredients.

Products that do not meet the criteria to be called ice cream are labelled
"frozen dairy dessert" instead. In other countries, such as Italy and
Argentina, one word is used for all variants.Analogues made from dairy
alternatives, such as goat's or sheep's milk, or milk substitutes, are
available for those who are lactose intolerant, allergic to dairy protein,
or vegan. The most popular flavours of ice cream in North America (based
on consumer surveys) are vanilla and chocolate.

如果我在控制台中复制上面的字符串,那么它只需要第一句话,然后对其进行评估。我想将整个段落作为字符串获取。这可能吗,我在这方面尝试了很多,但它只删除了句子中的空格。所以如果我们删除单词之间的空格就没有任何意义。我想删除句子和段落之间的空格 .谁能帮帮我?

最佳答案

使用正则表达式:

myText.trim().replaceAll("\\s+", " ");

关于java - 删除句子和段落之间的各种额外空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23357446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com