Reputation: 1
I am doing a project on encryption using a key less approach. I am struck while storing a textual paragraph containing a series of sentences into a string.My requirement is to store each sentence of the paragraph into string separately.
For example: If the paragraph contains,
"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."
The requirement is to store "Hello Indians,today is good day for you." in str[0] ,"We are the champions of the world cricket." in str[1] and so on. Can anyone please help me as early as possible to tackle this problem.
Upvotes: 0
Views: 2718
Reputation: 9783
Use paragraph.split(".")
, if you are sure, that each sentence ends with ".". paragraph
is a String
, containing all your sentences. split(".")
returns a String[]
, i call it sentences
, where the first element (sentences[0]
) contains the part from begining to the first ".", the second element (sentence[1]
) contains the sentence from first to second "."
Upvotes: 0
Reputation: 3360
......
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(".");
......
This should be what you're looking for
Upvotes: 0
Reputation: 8058
The String.split()
method is what you are in search of. Try this:
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);
}
}
Upvotes: 1