In java. Java. io. the StringTokenizer class can parse a single string. split in jdk1.4 can also parse a single string, but cannot parse the Reader stream, when parsing multiple characters, it cannot return a string that separates two strings. The following class is written to solve this problem. You can also prepare some basic parsing types, * and?
You can set multiple splits for resolution. The corresponding split string is returned during resolution.
Programs can run directly
/** Creation date: ** Change the generated file template to * window> Preferences> Java> code generation> code and comments */package com. csii. template;
Import java. io. IOException; import java. io. InputStreamReader; import java. io. Reader; import java. io. StringReader; import java. util. Iterator;
/*** @ Author wsl *** change the template of the generated type annotation to * window> Preferences> Java> code generation> code and comments */public class ReaderToken implements Iterator {
Private Reader reader = null; // stores the resolved Shard stream private String [] splits = null; // you can specify the token private StringBuffer HasRead = new StringBuffer () to separate the Shard stream (); // store the characters that have been read from the stream. private String [] splitsSf = null; // because there may be some wildcard characters, the wildcard characters in the token are stored here, for example, in 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] = "";}}
/* (Non-Javadoc) * @ see java. util. iterator # hasNext () */public boolean hasNext () {if (indexOf ()>-1) {return true;} return false;} private int currentsplit =-1; private int indexOf (){
Currentsplit =-1; int [] pos = new int [splits. length]; for (int I = 0; I <pos. length; I ++) {splitsSf [I] = ""; pos [I] = 0;} // initial position symbol
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.