This article mainly introduces Java's implementation of the word extraction function for a line of English, and analyzes the related operating skills of Java's string segmentation based on the StringTokenizer class in the form of examples. Friends in need can refer to this article
The example describes the Java implementation of word extraction function for a line of English. Share it with everyone for your reference, the details are as follows:
package fanyi; import java.util.Scanner; import java.util.StringTokenizer; public class text { public static void handle(String eString) { StringTokenizer st = new StringTokenizer(eString,",!' '.;"); while(st.hasMoreElements()) { System.out.println(st.nextElement()); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入英文文本:"); String eText = sc.nextLine(); handle(eText); //System.out.println(eText); } }
Running results:
The above is the detailed content of How to implement word extraction function for a line of English in Java. For more information, please follow other related articles on the PHP Chinese website!