Home > Java > javaTutorial > How to implement word extraction function for a line of English in Java

How to implement word extraction function for a line of English in Java

黄舟
Release: 2017-10-19 09:45:58
Original
2286 people have browsed it

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);
  }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template