Analyze the string and break it into words that can be used independently. These words are called language symbols. For example, for the string "We are struts", if spaces are used as the separator for this character
The string contains three words (language symbols ).
Constructor:
A) stringtokenizer (string s) -- constructs an analyzer for string S and uses the default delimiter, including space, line feed, carriage return, and tab.
B) stringtokenizer (string S, string delim) -- constructs an analyzer for string S. Any permutation and combination of Characters in the parameter 'delimiter' is a separator.
Hasmoretokens () method returns true if the value of the variable to be counted is greater than 0. Otherwise, false is returned.
Stringtokenizer Fenxi = new stringtokenizer ("99999.9999 ",".");
For (int I; Fenxi. hasmoretokens (); I ++ {
String STR = Fenxi. nexttoken ();
System. Out. println (STR );
}
Returns a token by intercepting a substring of a string, which is used to create a stringtokenizer object.
Code:
- // The following is an instance using tokenizer. The Code is as follows:
- Stringtokenizer ST = new stringtokenizer ("this is a test ");
- While (St. hasmoretokens ()){
- System. Out. println (St. nexttoken ());
- }
- // Output the following string:
- This
- Is
- A
- Test
- // Stringtokenizer is a legacy class reserved for compatibility reasons (although it is not encouraged in new code ). We recommend that you use the string split method or
- Java. util. RegEx package.
- // The following example illustrates how to use the string. split method to break the string into basic tags:
- String [] result = "this is a test". Split ("// s ");
- For (INT x = 0; x <result. length; X ++)
- System. Out. println (result [x]);
- /* Output the following string:
- This
- Is
- A
- Test */