[英]How to store each sentence of a paragraph in a string in java?
我正在做一个使用少密钥方法进行加密的项目。 我在将包含一系列句子的文本段落存储到字符串中时感到震惊,我的要求是将该段落的每个句子分别存储在字符串中。
例如:如果该段中包含“今天的印第安人,你好,今天是您的好日子。我们是世界板球运动的冠军。这是值得庆祝的时刻。请享受这一刻。” 要求是存储“ Hello Indians,今天对您来说是美好的一天”。 在str [0]中,“我们是世界板球的冠军。” 在str [1]中,依此类推。 任何人都可以尽早帮助我解决这个问题。
您正在寻找String.split()
方法。 尝试这个:
public static void main(String[] args) {
for (String sentence : "Hello Indians,today is good day for you. We are the champions of the world cricket.Here is the time for celebration.Enjoy the moment.".split("[.]")) {
System.out.println(sentence);
}
}
......
String yourinput = "Hello Indians,today is good day for you. We are the champions of the world cricket.Here is the time for celebration.Enjoy the moment.";
String[] str = yourinput.split(".");
......
这应该是您要寻找的
如果您确定每个句子都以“。”结尾,请使用paragraph.split(".")
。 paragraph
是一个String
,包含所有句子。 split(".")
返回一个String[]
,我称它为sentences
,其中第一个元素( sentences[0]
)包含从开始到第一个“。”的部分,第二个元素( sentence[1]
)包含从第一句到第二句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.