Home  >  Article  >  Java  >  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

黄舟
黄舟Original
2017-10-19 09:45:582250browse

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!

Statement:
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