Posted By:
David_Bates
Posted On:
Thursday, March 6, 2003 05:29 AM
If I understand you correctly (by the way, when you post your code, put it between
tags so it is formatted correctly), then you want to be able to print out a sentence at a time. This isn't too bad. All you have to do is set the delimiter of StringTokenizer to be the full-stop:
import java.util.*;
public class RunTest {
public static void main(String[] args) {
String str = "First sentence. Second Sentence. Third sentence.";
StringTokenizer st = new StringTokenizer(str, ".");
while (st.hasMoreTokens()) {
String sentence = st.nextToken();
System.out.println("Sentence: '" + sentence.trim() + ".'");
}
}
}
will output:
C:>java RunTest
Sentence: 'First sentence.'
Sentence: 'Second Sentence.'
Sentence: 'Third sentence.'
Note: The second argument to the StringTokenizer constructor dictates what the string delimiter.
Hope this helps,
David.