In Java. The Java.io.StringTokenizer class in Util can parse a single string, split in jdk1.4 can parse a single string, but cannot parse the reader stream, nor can you return a string that splits two strings when multiple character parsing, the following class is To solve this problem, it can also be prepared to include some of the most basic analytic types, * and?
You can set up multiple split to parse and return the corresponding split string when parsing
Programs can be run directly
* * Creation Date 2005-4-4 * * Change the generated file template for * window > Preferences > Java > Code generation > Codes and annotations */package com.csii.template;
/** * @author WSL * * Change the template for the generated type annotation to * window > Preferences > Java > Code generation > Code and Annotations */public class Readertoken implements Ite Rator {
Private Reader reader = null;//store ready to parse the character stream private string[] splits = null;//Prepare token private stringbuffer for dividing character streams hasread = New StringBuffer ()//hold characters that have been read from the stream private string[] SPLITSSF = null;//because of the possible presence of wildcard characters, the wildcard character is stored here, as in token abcdefgh * * /Public Readertoken (Reader Reader, string[] split) {super (); This.reader = reader; This.splits = split; SPLITSSF = new String[split.length]; for (int i = 0; i < split.length i++) {Splitssf[i] = ""; } }
Currentsplit =-1; Int[] pos = new Int[splits.length]; for (int i = 0; i < pos.length i++) {Splitssf[i] = ""; Pos[i] = 0; }//Preliminary position symbol
If the length within the current POS reaches the maximum splits inside, return the current split}}
Char Readchar = (char) reader.read ();
if (Readchar = = 1) {return currentsplit; }
if (Readchar = = 65535) {return currentsplit; }
Hasread.append (Readchar);
for (int i = 0; i < pos.length; i++) {
Char Splitposchar = Splits[i].charat (Pos[i]);
if (Splitposchar = = Readchar) {pos[i]++; Splitssf[i] + = Readchar; else if (Splitposchar = = ' * ') {char Nextchar = Splits[i].charat ((pos[i) + 1)); To get a character followed by the *, General wildcard characters are expressed as 1*2 if (Nextchar = = Readchar) {pos[i]++; pos[i]++; } Splitssf[i] + = Readchar; else if (Splitposchar = '? ') {pos[i]++; Splitssf[i] + = Readchar; } else {
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.