| |
2. 23. 2. Delimiters are comma, space, or period: '[, .]' |
|
public class MainClass {
public static void main(String[] arg) {
String text = "To be or not to be, that is the question.";
String delimiters = "[, .]"; // Delimiters are comma, space, and period
int[] limits = { 0, -1 }; // Limit values to try
for (int limit : limits) {
System.out.println("\nAnalysis with limit = " + limit);
String[] tokens = text.split(delimiters, limit);
System.out.println("Number of tokens: " + tokens.length);
for (String token : tokens) {
System.out.println(token);
}
}
}
}
|
|
Analysis with limit = 0
Number of tokens: 11
To
be
or
not
to
be
that
is
the
question
Analysis with limit = -1
Number of tokens: 12
To
be
or
not
to
be
that
is
the
question |
2. 23. 字符串记号化 | | 2. 23. 1. | Tokenizing字符串 | | | | 2. 23. 2. | Delimiters are comma, space, or period: '[, .]' | | |
|